Encircular
Learn this problemProblem statement
Build a computer simulation of a mobile robot. The robot moves on an infinite plane, starting from position
(0, 0). Its movements are described by a command string consisting of one or more of the following three letters:
G instructs the robot to move forward one step.L instructs the robot to turn left in place.R instructs the robot to turn right in place.The robot performs the instructions in a command sequence in an infinite loop. Determine whether there exists some circle such that the robot always moves within the circle.
Consider the commands R and G executed infinitely. A diagram of the robot's movement looks like:
The robot will never leave the circle.
Function
doesCircleExist(commands: String[]) → String[]Complete the function doesCircleExist in the editor below. The function must return an array of n strings either YES or NO based on whether the robot is bound within a circle or not, in order of test results.
doesCircleExist has the following parameter(s):
commands[commands[0],...commands[n-1]]: An array of n commands[i] where each represents a list of commands to test.Examples
Example 1
commands = ["G", "L", "RGRG"]return = ["NO", "YES", "YES"]Constraints
1 <= |commands[i]| <= 25001 <= n <= 10Each command consists of G, L, and R only.More Goldman Sachs problems
- Data ReorganizationSeen Jul 2026
- Inherited Role PermissionsONSITE INTERVIEW · Seen Jul 2026
- Root of the Largest TreePHONE SCREEN · Seen Jul 2026
- Validate Binary Search TreeONSITE INTERVIEW · Seen Jul 2026
- Alternating Parity PermutationsOA · Seen Jul 2026
- Threshold AlertsSeen Jul 2026
- Cheapest Flights Within K StopsONSITE INTERVIEW · Seen Jun 2026
- Word LadderPHONE SCREEN · Seen Jun 2026