This is a verified interview question from Sap-labs. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Robot Room Cleaner - Sap Labs Online Assessment Manipal University" covers key patterns like Arrays.
"You are given an unknown rectangular room represented as a grid. Each cell is either: * An empty cell that the robot can move through. * A blocked cell that the robot cannot enter. A robot starts from an unknown empty cell, initially facing one of the four cardinal directions (up, right, down, or left). The layout of the room is **not available** to your program. Instead, you can interact with the robot only through the following operations: * Move forward by one cell. * Rotate left by 90°. * Rotate right by 90°. * Clean the current cell. If the robot attempts to move into a blocked cell, it remains in its current position. Your task is to clean **every reachable empty cell** exactly once or more using only these operations. Implement the required algorithm to ensure that all reachable cells are cleaned. --- ## Robot Interface The following operations are available: ```cpp bool move(); // Moves forward if possible. // Returns true if the move succeeds, otherwise false. void turnLeft(); // Rotates the robot 90° to the left. void turnRight(); // Rotates the robot 90° to the right. void clean(); // Cleans the current cell. ``` --- ## Function Signature ```cpp void cleanRoom(Robot& robot); ``` --- ## Constraints * The room dimensions are at most `100 × 200`. * The starting cell is guaranteed to be empty. * The room layout is unknown to your algorithm. * All robot operations run in constant time. --- ## Notes * You **must not** assume access to the room grid or the robot's coordinates. * The robot's initial position and initial facing direction are unknown. * The solution should visit every reachable empty cell and invoke `clean()` on each of them. ---"
Join thousands of developers practicing for Sap-labs.