A patrol bot starts at the origin facing North and repeats a fixed instruction cycle forever. Each instruction is one character:
G: move forward one unit in the current facing direction,L: turn 90 degrees to the left (counter-clockwise), staying in place,R: turn 90 degrees to the right (clockwise), staying in place.The bot is bounded if there exists some circle it never leaves no matter how many times the cycle repeats; otherwise it drifts away forever.
A single line: a non-empty string of characters, each one of G, L, R (one full instruction cycle).
Print YES if the bot stays bounded, otherwise print NO.
Example 1
Input
GGLLGG
Expected
YES
Explanation
The bot goes forward twice, turns around, then goes forward twice, returning to the origin, so it is bounded.
Example 2
Input
GG
Expected
NO
Explanation
The bot moves two units North and still faces North, so each cycle pushes it further away and it is unbounded.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →