Final Position from Direction Commands
Updated
Problem statement
Start at coordinate (0, 0) and process commands from left to right. The letters L, R, U, and D move one unit left, right, up, and down. Lowercase forms have the same meaning. Ignore every other character.
Return [x, y] after all commands.
Function
finalCoordinates(commands: String) → int[]Examples
Example 1
commands = "LRUDx"return = [0,0]The four moves cancel and x is ignored.
Example 2
commands = "RRuLdd?"return = [1,-1]Commands are case-insensitive and ? is ignored.
Constraints
0 <= commands.length <= 1000000commandscontains ASCII characters.
More Goldman Sachs Phone Screen questions
- Best Average Student ScorePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Hash MapOA · PHONE SCREEN · Seen Nov 2026
- House Robber IIIPHONE SCREEN · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · Seen Nov 2026
- Check a Complete Binary TreePHONE SCREEN · Seen Oct 2026
- Meeting RoomsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Count Staircase WaysPHONE SCREEN · Seen Oct 2026
- Is a Power of TenPHONE SCREEN · Seen Oct 2026
- Minimum Traveling Salesperson TourPHONE SCREEN · Seen Oct 2026
- Square Root with Newton IterationPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Container Ledger with TradesFlexport · ONSITE INTERVIEWFlexport interview questions
- Christmas Tree with N TiersVerily · ONSITE INTERVIEW
- Search and Format ContactsAdyen · PHONE SCREENAdyen interview questions
- Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
- Portfolio Valuation, Part 1Stripe · PHONE SCREENStripe interview questions
- Format a Signed Integer with CommasHudson River Trading · PHONE SCREENHudson River Trading interview questions
- Fair Coin from a Biased CoinAnthropic · PHONE SCREENAnthropic interview questions
- Bounded Word Guess SolverAtlassian · ONSITE INTERVIEWAtlassian interview questions
- Run-Length DecodingApple · PHONE SCREENApple interview questions
- Trace Pointer Rebinding and Pointee UpdatesArista Networks · PHONE SCREENArista Networks interview questions