Encircular
Updated
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.
More Goldman Sachs interview questions
- House Robber IIIPHONE SCREEN · Seen Nov 2026
- Knight Probability in ChessboardONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · Seen Nov 2026
- Maximum Ones After K OperationsOA · Seen Nov 2026
- Palindrome CounterOA · Seen Oct 2026
- Longest Palindromic SubsequenceOA · Seen Oct 2026
- Best Average Student ScorePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Check a Complete Binary TreePHONE SCREEN · Seen Oct 2026
- Meeting RoomsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Minimum Meeting Rooms Without a Sweep LineONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Last Object Exit TimeIBM · OAIBM interview questions
- Capping Portfolio WeightsCapstone Investment Advisors · OA
- Bold Play to Reach a GoalSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Repeated Mirror XORMathWorks · OAMathWorks interview questions
- Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
- Find Total CostJP Morgan Chase · OAJP Morgan Chase interview questions
- Macaron Order PriceOpenAI · OAOpenAI interview questions
- Daily Settlement for Long and Short PositionsBelvedere Trading · OA
- Debug the Risk-Limit QuoterMillennium · OAMillennium interview questions
- Prime Factor VisitationMaven Securities · OAMaven Securities interview questions