FastPrepEncircular
Problems/Encircular

Encircular

Goldman Sachs logoGoldman Sachs● MediumNEW GRADINTERNOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

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 direction
  • L: turn left by 90 degrees without moving
  • R: 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"]
  1. G moves forward forever, so its result is NO.
  2. L only rotates at the origin, so its result is YES.
  3. Repeating RGRG follows a bounded path, so its result is YES.

Constraints

  • 1 <= commands.length <= 10
  • 1 <= commands[i].length <= 2500
  • Each command contains only G, L, and R.

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
All Goldman Sachs interview questionsSee Goldman Sachs hiring insights
Saved
class Solution {
    public String[] doesCircleExist(String[] commands) {
      // write your code here
    }

}
Checking account…