Final Position after Grid Commands
Updated
Problem statement
Start at (0,0), facing north, on an unbounded integer grid. Each command is L (turn left 90 degrees), R (turn right 90 degrees), or F k (move forward k units without turning). East increases x and north increases y. Return [x,y] after all commands. Turns do not move you; no obstacles exist.
Function
finalPosition(commands: String[]) → long[]Examples
Example 1
commands = ["F 3","R","F 2"]return = [2,3]Move north three units, then east two.
Example 2
commands = ["L","F 2","R","F 1"]return = [-2,1]A left turn initially points west.
Constraints
- For this exercise, assume at most 100000 commands, with 0 <= k <= 1000000, written as F followed by one space and an integer without extra characters.
- The coordinate sum fits signed 64-bit integers.
More Intuit Online Assessment questions
- Employee Promotion OpportunitiesOA · Seen Oct 2026
- Next Pascal Row CoefficientOA · Seen Oct 2026
- Parse Router LogsOA · Seen Oct 2026
- Longest Repeated Letter Block with Adjacent SwapsOA · Seen Oct 2026
- Maximum Square-Free DivisorOA · Seen Oct 2026
- Two Tribes from Taller-Person CountsOA · Seen Oct 2026
- Shortest Path from an Encoded GraphOA · Seen Sep 2026
- Oldest and Youngest EmployeesOA · Seen Sep 2026
- Pressure-Isolation Shutdown OrderOA · Seen Sep 2026
- Submask Sum QueriesOA · Seen Sep 2026
Similar questions at other companies
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Book Reading EveningsGoogle · OAGoogle interview questions
- Basic Item DiscountsPalantir · OAPalantir interview questions
- Wind-Blown Leaves Remaining in a GridAbridge · OAAbridge interview questions
- Shell Command Counts with History ReferencesTikTok · OATikTok interview questions
- Count Dropped RequestsJP Morgan Chase · OAJP Morgan Chase interview questions
- Recursively Expanded Shell Command CountsHudson River Trading · OAHudson River Trading interview questions
- Diagonal Bounce TraversalAutodesk · OAAutodesk interview questions
- First Value Below Both NeighborsCapital One · OACapital One interview questions
- REST API: Highest International StudentsRippling · OARippling interview questions