Clean Every Reachable Cell With a Robot That Has No Map

Last updated: November 29, 2026

Quick Overview

You control a cleaning robot through an API with move() (returns False if blocked), turn_left(), turn_right() and clean(). The robot does not know the room layout or its own position. Clean every reachable cell.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


You control a cleaning robot through an API with move() (returns False if blocked), turn_left(), turn_right() and clean(). The robot does not know the room layout or its own position. Clean every reachable cell.

Meta hardware and Reality Labs teams care about robots and devices exploring unknown spaces, and this question is a well-known hard backtracking problem in Meta onsites. The interviewer checks that you invent a relative coordinate frame, track orientation consistently, and physically backtrack the robot.

What the Interviewer Expects
  • Use relative coordinates starting at (0, 0)
  • Keep direction indexes aligned with turn_right order
  • Mark visited cells in a set before exploring
  • Physically return to the previous cell and restore orientation
  • Prove every reachable cell is visited and the robot ends at start
Key Topics to Cover
Backtracking
Depth-first search
Interactive problems
Coordinate systems
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you minimize the number of moves instead of just covering?
  • What if move() can fail randomly even when the cell is open?
  • How would you also build and return a map of the room?
  • How would two robots share the work?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Room is a grid of open and blocked cells, unknown to us.
  • Start cell is open; the robot faces some unknown direction we call up.
  • Use only the four API calls; clean every cell reachable from the s...
High-Level Design

Define the starting cell as (0, 0) and the starting heading as direction 0, with directions listed clockwise so turn_right advances the index. DFS from a cell: clean it, then for each of the four ...


Submit Your Answer
Markdown supported