This question evaluates spatial reasoning, state and command parsing, collision detection, boundary handling, and API design for extensible simulation across 2D and 3D coordinate systems.
You are building a rover navigation simulator.
You are given:
(x, y)
.
(x0, y0)
and a facing direction (one of
N, E, S, W
).
L
: turn left 90°
R
: turn right 90°
M
: move forward 1 step in the current facing direction
Rules:
Task: Implement a function that returns the rover’s final position and direction after executing all commands.
Extend the design to support multiple rovers on the same 2D map.
Task: Explain how you would change the code structure/API to support multiple rovers cleanly and safely.
Now the map is 3D with coordinates (x, y, z).
+X, -X, +Y, -Y, +Z, -Z
).
Task: Describe and/or implement how your solution generalizes to 3D while keeping the design maintainable.