Leetcode Problem 2061. Number of Spaces Cleaning Robot Cleaned
2061. Number of Spaces Cleaning Robot Cleaned
Leetcode Solutions
Simulation with Visited State Tracking
Initialize a set to track visited states, where each state is a tuple of the robot's position and direction.
Define the directions the robot can face and the corresponding movements.
Start the robot at the top-left corner of the room, facing right.
While simulating the robot's movement:
a. Move the robot one step in the current direction.
b. If the robot encounters an obstacle or the edge of the room, turn it 90 degrees clockwise.
c. If the robot moves into a cell in the same direction as a previous visit, end the simulation.
Return the number of unique cells visited by the robot.