← Pinterest Interview Insights

Pinterest·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026Remote

Summary

Pinterest coding interview, algorithm-heavy with a grid-based robot vacuum problem that had multiple variants. The question escalated fast and I wasn't fully prepared for the coordination part.

Questions Asked (2)

Q1

Given a 2D grid with obstacles and two robot vacuums each starting at a different cell, how would you compute the union of all cells reachable by either robot? Each robot can move in 8 directions.

Algorithms & Data Structures
Author's notes

Part (a) felt manageable.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the grid as a graph where each cell is a node and edges connect to its 8 neighbors if they are not obstacles. Run a BFS or DFS from each robot's starting cell to find all reachable cells, then take the union of the two sets. Return the count or the set of unique cells.

Pro tip: Clarify whether the robots can occupy the same cell and whether obstacles are static; this shows attention to detail and avoids incorrect assumptions. Also, mention that using a single visited set for both BFS runs can save memory and time.

1. Clarify problem details

Ask about grid size, obstacle representation, robot starting positions, and whether movement is simultaneous or independent. Confirm that reachability is independent for each robot.

2. Choose traversal algorithm

Select BFS or DFS for reachability. BFS is often preferred for shortest path but either works for reachability; mention trade-offs like recursion depth for DFS.

3. Implement traversal with visited set

Use a queue (BFS) or stack (DFS) and a visited set to avoid revisiting cells. For each robot, start from its initial cell and explore all 8 directions, skipping obstacles and out-of-bounds cells.

4. Compute union and return result

After both traversals, combine the visited sets (e.g., using set union) to get all reachable cells. Return the count or the set itself as required.

5. Analyze complexity and optimize

State time complexity O(R*C) and space O(R*C) for visited set. Suggest optimizations like early termination if one robot covers all cells or using a single visited set for both robots.

Key Points to Mention

  • Graph representation: cells as nodes, 8-directional edges to non-obstacle neighbors
  • BFS/DFS traversal with visited set to avoid cycles and redundant work
  • Union operation: combine reachable sets from both robots, e.g., using set union or a shared visited set
  • Time and space complexity: O(R*C) time and space, where R and C are grid dimensions
  • Edge cases: robot starts on obstacle, no obstacles, grid boundaries, robots starting at same cell
  • Optimization: use a single visited set for both BFS runs to save memory and time

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

Q2

Now coordinate the two robots so they together clean every reachable cell, optimizing for either minimum total moves or minimum makespan (the longer of the two individual paths). How does your approach change based on which cost metric you pick?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is where things went sideways for me.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the environment as a graph, compute reachable cells via BFS, then formulate the multi-robot coverage problem as an optimization over partitions and schedules. For minimum total moves, minimize the sum of individual path lengths; for minimum makespan, minimize the maximum individual path length. Discuss how the objective changes the partitioning strategy and coordination.

Pro tip: Mention that minimizing total moves often leads to unbalanced partitions (one robot does most work) while minimizing makespan requires balancing the load, and that the latter is generally harder (NP-hard) but can be approximated with heuristics like binary search on makespan.

1. Model the problem

Represent the environment as a graph where nodes are cells and edges are valid moves. Identify all reachable cells from the robots' start positions using BFS or DFS.

2. Define cost metrics

Clearly define total moves as the sum of moves made by both robots, and makespan as the maximum of the two robots' move counts. Explain that these metrics lead to different optimization goals.

3. Partition and schedule

For minimum total moves, assign cells to robots to minimize the sum of path lengths, possibly using a greedy or dynamic programming approach. For minimum makespan, balance the workload by partitioning cells into two sets with roughly equal coverage times, using binary search on the makespan and checking feasibility.

4. Coordinate and avoid conflicts

Plan paths that avoid collisions and redundant coverage. For makespan, synchronize movements so both robots finish simultaneously; for total moves, allow one robot to idle if it reduces overall moves.

5. Analyze trade-offs and complexity

Discuss the computational complexity: minimum total moves can be solved optimally for small instances but is NP-hard in general; minimum makespan is also NP-hard but can be approximated. Mention that the choice depends on the application's priority.

Key Points to Mention

  • Graph representation and BFS for reachable cells
  • Difference between total moves (sum) and makespan (max)
  • Partitioning strategies: unbalanced vs balanced
  • NP-hardness of multi-robot coverage
  • Heuristics: binary search on makespan, greedy assignment
  • Collision avoidance and synchronization

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