Clean every reachable cell with a blind robot that can only move, turn and clean
Problem
A robot vacuum is placed in a room it cannot see. It does not know the layout or its position. It only has four commands:
// Room (1 = open, 0 = wall), robot starts at row 1, column 3:
// 1 1 1 1 1 0 1 1
// 1 1 1 1 1 0 1 1
// 1 0 1 1 1 1 1 1
// 0 0 0 1 0 0 0 0
// 1 1 1 1 1 1 1 1
cleanRoom(robot); // every open cell connected to the start gets cleanedRef. UR-1428 · © UIRound · uiround.com/questions/clean-every-reachable-cell-with-a-blind-robot-that-can-only-move-turn-and-clean
Unlock this question
The full problem, its tests and the tested solution are part of Pro.
- 2
- code listings
- 4
- edge cases
What's inside
- The full problem, with examples
- Tests that check your solution
- Step-by-step
- Approach
- Solution
- Complexity
- Edge cases
- Follow-up questions
- Card worldwide
- UPI and net banking in India
- One-time payment, nothing renews
Stuck? Take a hint
- 1You never see the map or your position, so invent coordinates: call the start (0, 0) and track your own position and facing as you move. A Set of visited cells is then your map.
Try it in the editor
Run your code as often as you like. Submitting it to the full test suite is part of Pro.
Private, and saved in this browser as you type. All your notes are on My lists.