← Pinterest Interview Insights

Pinterest·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Pinterest coding screen, robot vacuum problem on a 2D grid. Pretty focused session, just the one problem but they pushed on edge cases more than I expected.

Questions Asked (1)

Q1

A robot vacuum on a 2D grid can move in 8 directions. Given a single obstacle cell and a starting position, return all cells reachable from the start using BFS or DFS.

Algorithms & Data Structures
Author's notes

I went with BFS, which felt natural.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the grid boundaries and whether the obstacle is passable, then choose BFS or DFS to traverse the 8-directional neighbors. Use a visited set to avoid revisiting cells, and return the set of reachable cells excluding the start and obstacle.

Pro tip: Mention that BFS is preferable for finding shortest paths, but since the question only asks for reachable cells, DFS is equally valid and may be simpler to implement iteratively. Also, explicitly handle edge cases like the start being the obstacle or out of bounds.

1. Clarify the problem

Ask about grid dimensions, whether the obstacle is passable, and if the start can be the obstacle. Confirm that movement is allowed in all 8 directions and that cells are considered reachable if there is a path avoiding the obstacle.

2. Choose traversal method

Decide between BFS (queue) or DFS (stack/recursion). Both work; BFS naturally explores level by level, while DFS may use less memory for deep paths. Mention that the choice doesn't affect correctness here.

3. Implement traversal with visited set

Initialize a queue or stack with the start cell and a visited set containing the start. While the structure is not empty, pop a cell, add it to the reachable set, and for each of the 8 neighbors, if it's within bounds, not the obstacle, and not visited, add it to the structure and mark visited.

4. Handle edge cases and return result

Check if the start is the obstacle or out of bounds; if so, return an empty set. Otherwise, return the visited set (which includes the start) or exclude the start if specified. Ensure the obstacle is never added.

Key Points to Mention

  • Grid boundaries and coordinate system (e.g., 0-indexed, rows and columns)
  • 8-directional movement: list the 8 neighbor offsets (dx, dy)
  • Use of a visited set to avoid infinite loops and redundant work
  • Time and space complexity: O(R*C) time and space in the worst case
  • Handling of the obstacle: it is impassable and should not be added to reachable cells
  • Edge cases: start equals obstacle, start out of bounds, obstacle out of bounds, empty grid

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.