Encircular
Problem statement
A robot starts at (0, 0) on an infinite plane and initially faces north. A command string contains only:
G: move forward one unit in the current directionL: turn left by 90 degrees without movingR: turn right by 90 degrees without moving
The robot repeats the entire command string forever. A command is circular if the robot always remains inside some finite circle.
For every string in commands, return "YES" if its repeated path is circular, or "NO" otherwise, preserving input order.
Function
doesCircleExist(commands: String[]) → String[]Examples
Example 1
commands = ["G", "L", "RGRG"]return = ["NO", "YES", "YES"]Gmoves forward forever, so its result isNO.Lonly rotates at the origin, so its result isYES.- Repeating
RGRGfollows a bounded path, so its result isYES.
Constraints
1 <= commands.length <= 101 <= commands[i].length <= 2500- Each command contains only
G,L, andR.