OnACircle
TCO22 Wildcard · 2022-04-14 · by misof
Problem Statement
The
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
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').
"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.
"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'.
"abcdef" "bde" Returns: 0
We are not allowed to skip letters. It is not possible to read "bde" anywhere on this cycle.
"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'.
"abcdef" "cbafedcb" Returns: 1
We can make more than one full loop around the circle.
"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.
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