The Number of Spaces Cleaning Robot Cleaned problem simulates a cleaning robot moving through a grid. The robot starts at the top-left corner facing right, moves forward until it hits a wall or obstacle, then turns right and continues. Count how many unique grid spaces the robot cleans. This is a simulation with direction tracking and visited set management.
Microsoft and Geico ask this to test simulation design and the ability to detect the termination condition (when the robot returns to a previously visited state — same position and direction). The array, matrix, and simulation interview pattern is the core.
Simulation with state cycle detection. Simulate robot movement step by step. At each step, track (row, col, direction) as the state. If the robot attempts to move into a wall or obstacle, turn right instead. Add each cleaned cell to a visited set. Terminate when the robot re-enters a previously seen (position, direction) state (cycle detected). Return the visited cell count.
Grid with obstacles, robot starts at (0,0) facing right.
Robot simulation problems need three components: (1) direction vectors [(0,1),(1,0),(0,-1),(-1,0)] for right/down/left/up, (2) a visited state set including direction, (3) clean cycle termination. The direction index (dir_idx % 4) handles turning elegantly. Practice grid robot simulation problems of increasing complexity — from simple movement to obstacle avoidance to cycle detection. These appear frequently in simulation-based interview rounds.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Queens That Can Attack the King | Medium | Solve | |
| Count Unguarded Cells in the Grid | Medium | Solve | |
| Spiral Matrix III | Medium | Solve | |
| Spiral Matrix II | Medium | Solve | |
| Diagonal Traverse | Medium | Solve |