Connection Status:
Competition Arena > OnACircle
TCO22 Wildcard · 2022-04-14 · by misof · Brute Force, Simple Search, Iteration, String Manipulation
Class Name: OnACircle
Return Type: int
Method Name: canRead
Arg Types: (string, string)
Problem Statement

Problem Statement

The String circle is written around a circle in the clockwise direction.


Now that you have the circle, you can read a new string by starting anywhere on the circle and then walking along the circle and reading all the letters you encounter. You may terminate the process whenever you want. You may walk around the circle in either direction (clockwise or counter-clockwise) but you are not allowed to change direction while walking.


Given is a String goal. Determine whether goal can be read when following the above instructions. You get to choose where on the circle you start, in which direction you walk and when to stop reading.

Return 1 if goal can be read, or 0 if it does not.

Constraints

  • circle will contain between 3 and 2500 characters, inclusive.
  • Each character in circle will be a lowercase English letter ('a'-'z').
  • goal will contain between 1 and 2500 characters, inclusive.
  • Each character in goal will be a lowercase English letter ('a'-'z').
Examples
0)
"abcdef"
"bcd"
Returns: 1

The circle can look roughly as follows: a--b / \ f c \ / e--d We can read "bcd" by starting at the only 'b', going clockwise and stopping after the third read letter.

1)
"abcdef"
"dcb"
Returns: 1

The same circle as in the previous example. We can read "dcb" by essentially doing the same thing we did in the previous example, only in reverse: we start at the 'd', walk counter-clockwise, and stop after reading 'b'.

2)
"abcdef"
"bde"
Returns: 0

We are not allowed to skip letters. It is not possible to read "bde" anywhere on this cycle.

3)
"abcdef"
"efabc"
Returns: 1

Here's the circle again. a--b / \ f c \ / e--d We can read "efabc" by starting at the only 'e', going around the circle clockwise and stopping after the 'c'.

4)
"abcdef"
"cbafedcb"
Returns: 1

We can make more than one full loop around the circle.

5)
"abcdef"
"aba"
Returns: 0

Changing direction while reading is not allowed.

Submissions are judged against all 251 archived test cases, of which 6 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class OnACircle with a public method int canRead(string circle, string goal) · 251 test cases · 2 s / 256 MB per case

Submitting as anonymous