This question evaluates competency in grid-based simulation, state updates, boundary condition handling, and sequential command parsing. Commonly asked in Coding & Algorithms interviews to gauge correct implementation and edge-case reasoning, it assesses practical application more than abstract theory and can be extended to path reconstruction or obstacle-aware movement as follow-ups.
You are given an m x n grid and a robot that starts at position (r, c) (0-indexed). You are also given a string commands consisting of characters 'U', 'D', 'L', 'R', where each character requests moving the robot one cell up/down/left/right.
Rules:
Return the robot’s final position (r, c) after processing all commands.
Follow-ups (if time): return the full path; handle blocked cells where moves into obstacles are ignored.