PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCareers
|Home/Coding & Algorithms/Pinterest

Compute reachable cells for a cleaning robot

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of graph traversal, state-space modeling, and scalability when computing reachable cells on a 2D grid under 8-direction movement and variants that allow limited obstacle removal or multiple agents.

  • medium
  • Pinterest
  • Coding & Algorithms
  • Software Engineer

Compute reachable cells for a cleaning robot

Company: Pinterest

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given a 2D grid representing a floor plan: - `0` = free cell (the robot may stand on it) - `1` = blocked cell (obstacle) The robot can move from a cell to any of its **8 neighbors** (up, down, left, right, and 4 diagonals) as long as the destination cell is allowed under the rules of the sub-question. Return answers as a set/list of reachable coordinates `(r, c)` (order does not matter). ### Sub-question 1 (basic reachability) **Input:** grid `m x n` and a start cell `(sr, sc)` that is free. **Task:** return **all free cells** reachable from `(sr, sc)` using 8-direction moves. ### Sub-question 2 (one obstacle can be cleared) Same as Sub-question 1, except the robot may **convert at most one blocked cell (`1`) into free (`0`)** during its traversal (think: it can clear/remove one obstacle exactly once). **Task:** return all cells that are reachable under this rule. ### Sub-question 3 (two robots) **Input:** grid `m x n` and two start cells `(s1r, s1c)` and `(s2r, s2c)` that are free. **Task:** return the set of cells that are reachable by **at least one** of the two robots (union of their reachable areas) using 8-direction moves. ### Constraints (assume) - `1 <= m, n <= 2000` (choose an approach that is safe for large grids) - Grid is not necessarily fully connected. - Start cells are within bounds. Clarify in the interview how to represent the returned set for large outputs (e.g., boolean mask vs coordinate list).

Quick Answer: This question evaluates understanding of graph traversal, state-space modeling, and scalability when computing reachable cells on a 2D grid under 8-direction movement and variants that allow limited obstacle removal or multiple agents.

Related Interview Questions

  • Design Hierarchical Permission Checks - Pinterest (medium)
  • Implement weighted random choice - Pinterest (medium)
  • Solve five hard algorithm problems - Pinterest
  • Sample a string by real-valued scores - Pinterest (hard)
  • Find First Prefix-Matching Word - Pinterest (medium)
Pinterest logo
Pinterest
Jan 22, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
30
0
Loading...

You are given a 2D grid representing a floor plan:

  • 0 = free cell (the robot may stand on it)
  • 1 = blocked cell (obstacle)

The robot can move from a cell to any of its 8 neighbors (up, down, left, right, and 4 diagonals) as long as the destination cell is allowed under the rules of the sub-question.

Return answers as a set/list of reachable coordinates (r, c) (order does not matter).

Sub-question 1 (basic reachability)

Input: grid m x n and a start cell (sr, sc) that is free.

Task: return all free cells reachable from (sr, sc) using 8-direction moves.

Sub-question 2 (one obstacle can be cleared)

Same as Sub-question 1, except the robot may convert at most one blocked cell (1) into free (0) during its traversal (think: it can clear/remove one obstacle exactly once).

Task: return all cells that are reachable under this rule.

Sub-question 3 (two robots)

Input: grid m x n and two start cells (s1r, s1c) and (s2r, s2c) that are free.

Task: return the set of cells that are reachable by at least one of the two robots (union of their reachable areas) using 8-direction moves.

Constraints (assume)

  • 1 <= m, n <= 2000 (choose an approach that is safe for large grids)
  • Grid is not necessarily fully connected.
  • Start cells are within bounds.

Clarify in the interview how to represent the returned set for large outputs (e.g., boolean mask vs coordinate list).

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Pinterest•More Software Engineer•Pinterest Software Engineer•Pinterest Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • Careers
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.