LC: 489. Robot Room Cleaner - spiralgo/algorithms GitHub Wiki
The Essence:
The robot should move in 4 directions. The robot shouldn't move the tiles it has already visited to prevent retracing paths. After it moves, it should go back to its previous position to search other directions.
Details:
The movement of the robot corresponds to a DFS-Backtracking algorithm. For moving the robot, we not only need its position but its direction too. The set of visited tiles can be represented using any set data structure. The end condition of backtracking is not being able to move in any directions. This automatically ends the procedure at that tile. At the function call for the previous tile, the robot should then go back form this tile with its current direction to move in other directions.