As reported: Apple online assessment (2025): 17 questions — 15 multiple choice and 2 easy-to-medium coding questions; one of them was a walking-robot simulation.
A robot on an infinite XY-plane starts at (0, 0) facing north. It receives a list of commands:
-2: turn left 90 degrees;-1: turn right 90 degrees;1 ≤ k ≤ 9: move forwardkunits, one unit at a time.
Some grid squares are obstacles: obstacles[i] = (xi, yi). If the robot's next step would land on an obstacle, it stays where it is and moves on to the next command.
Return the maximum squared Euclidean distance from the origin that the robot reaches at any point.
North is +Y, east +X, south −Y, west −X. An obstacle may be at (0, 0); the robot ignores it until it leaves the origin, and cannot return there afterwards.
This is LeetCode 874 — Walking Robot Simulation.
Example 1
commands = [4,-1,3], obstacles = [] -> 25
The robot moves to (0, 4), turns right, moves to (3, 4): 3² + 4² = 25.
Example 2
commands = [4,-1,4,-2,4], obstacles = [[2,4]] -> 65
It is blocked at (1, 4), turns left and walks to (1, 8): 1 + 64 = 65.
Constraints: 1 ≤ commands.length ≤ 10^4; commands[i] is -2, -1 or in [1, 9]; 0 ≤ obstacles.length ≤ 10^4; −3 · 10^4 ≤ xi, yi ≤ 3 · 10^4; the answer is less than 2^31.
Code runner format: one JSON value per line: commands, then obstacles (LeetCode's test-case format). Implement robotSim(commands, obstacles); the harness prints the result.