🤖Robot Cleaner Problem!
Robot cleans room following rules. 1. Clean current cell 2. Check from left 3. If can't move, go backward 4. If can't go back, stop
Loading...
Robot cleans room following rules. 1. Clean current cell 2. Check from left 3. If can't move, go backward 4. If can't go back, stop
There is a robot cleaner in an N×M room. The robot moves according to these rules: 1. If current cell is not cleaned, clean it. 2. Starting from left of current direction: - If there's an uncleaned empty cell on the left, rotate and move forward - If not, keep rotating left 3. If all 4 directions are cleaned or walls: - If can move backward, move back and go to step 2 - If cannot (wall behind), stop operation Find the number of cells the robot cleans.
3 3 1 1 0 1 1 1 1 0 1 1 1 1
1
Robot starts at (1,1), can only clean current cell. All surroundings are walls or cannot be cleaned, so only 1 cell
4 4 1 1 0 1 1 1 1 1 0 0 1 1 0 0 1 1 1 1 1
4
Robot starts at (1,1) facing North. No empty cell on left(West), rotates and explores, cleans 4 cells