← Pinterest Interview Insights

Pinterest·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Pinterest SWE interview with a grid pathfinding problem that looks like a classic BFS until you realize you have to track which keys you've picked up. Took me a bit to get the state space right and the follow-up questions on correctness and edge cases kept coming.

Questions Asked (3)

Q1

You have a 2D grid of rooms where some cells are walls, some are open, some contain keys (lowercase letters), and some are locked doors (matching uppercase letters). Starting from a given cell, find the minimum number of steps to reach the exit. You can move in four directions, can't pass through a door without its key, and can revisit cells.

Algorithms & Data Structures
Author's notes

My first instinct was plain BFS and I started coding it before realizing state is wrong if you don't track which keys you have.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a shortest path search in a state space where each state includes the current position and the set of keys collected. Use BFS to explore states in order of steps, since each move has unit cost. When encountering a door, only proceed if the corresponding key is in the collected set.

Pro tip: Mention that the state space can be reduced by only tracking keys that are actually present on the map, and that BFS guarantees the first time you reach the exit is the minimum steps. Also, note that revisiting cells is allowed but with different key sets, so visited states must include the key set.

1. Clarify problem details

Ask about grid size, number of keys, whether multiple keys of the same type exist, and if the exit is always reachable. Confirm that doors require the exact key and that keys are consumed or not.

2. Define state representation

Represent each state as (row, col, keys_bitmask) where keys_bitmask encodes which keys have been collected. Use a bitmask for efficiency if the number of key types is small.

3. Apply BFS with state tracking

Use a queue for BFS, starting from the initial state. For each state, explore four directions; if the next cell is a wall, skip; if it's a door, only proceed if the key is in the bitmask; if it's a key, update the bitmask. Mark visited states to avoid cycles.

4. Return minimum steps

When the exit cell is reached, return the current step count as the minimum. If the queue empties without reaching the exit, return -1 or indicate unreachable.

5. Analyze complexity and optimizations

Discuss time complexity O(R*C*2^K) where K is number of key types, and space complexity similar. Mention potential optimizations like bidirectional BFS or A* if applicable.

Key Points to Mention

  • BFS is optimal for unweighted shortest path problems.
  • State must include both position and collected keys to handle revisiting with different keys.
  • Use a bitmask to efficiently represent the set of collected keys.
  • Doors act as conditional barriers: only passable if the corresponding key is held.
  • Visited states must be tracked to avoid infinite loops, but a cell can be visited multiple times with different key sets.
  • Time complexity is O(R*C*2^K) where K is the number of distinct keys.

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

Q2

Why is BFS the right algorithm here, and how does it guarantee the minimum number of steps?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Pretty straightforward once you frame it as an unweighted graph over states.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem context and why BFS is chosen over other algorithms like DFS or Dijkstra. Then explain the level-order traversal property of BFS and how it guarantees the shortest path in unweighted graphs, using a concrete example to illustrate.

Pro tip: Mention that BFS is optimal for unweighted graphs but not for weighted ones, and briefly note how you'd adapt if edge weights were introduced (e.g., Dijkstra). This shows you understand trade-offs and can anticipate follow-up questions.

1. Restate the problem and constraints

Briefly summarize the problem, emphasizing that it involves finding the minimum number of steps or shortest path in an unweighted graph or grid.

2. Explain why BFS is suitable

State that BFS explores nodes in increasing order of distance from the source, making it ideal for finding shortest paths in unweighted graphs.

3. Describe the level-order traversal

Explain how BFS processes nodes level by level, where each level corresponds to nodes at distance k from the source, ensuring the first time a target is reached, it's via the shortest path.

4. Contrast with alternatives

Mention that DFS might find a path but not necessarily the shortest, and Dijkstra's algorithm is overkill for unweighted graphs, though it generalizes BFS.

5. Conclude with the guarantee

Summarize that because BFS visits nodes in non-decreasing order of distance, the first time the destination is dequeued, the path length is minimal.

Key Points to Mention

  • BFS explores nodes in increasing order of distance from the source.
  • In unweighted graphs, BFS guarantees the shortest path in terms of number of edges.
  • The queue data structure ensures FIFO order, which is crucial for level-order traversal.
  • The first time a node is visited, it is via the shortest path; subsequent visits can be ignored.
  • BFS is optimal for unweighted graphs; for weighted graphs, Dijkstra's algorithm is needed.
  • Time complexity is O(V+E), which is efficient for many problems.

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

Q3

What are the edge cases your solution needs to handle for this problem?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I listed a few: no keys exist at all (bitmask stays zero, doors just block you), exit is unreachable, multiple exits (return the min across all of them).

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Systematically enumerate edge cases by category (input, boundary, structural, and performance) and explain how your solution handles each. Prioritize the most impactful edge cases for the problem and relate them to Pinterest's scale and data characteristics.

Pro tip: Tie edge cases to real-world scenarios at Pinterest, such as handling billions of pins or skewed user engagement, to show you think beyond correctness and consider production impact.

1. Clarify the problem and constraints

Restate the problem and ask clarifying questions about input size, data types, and expected behavior to identify potential edge cases.

2. Categorize edge cases

Group edge cases into categories: empty/null inputs, boundary values, duplicates, ordering, and structural extremes (e.g., very large or small inputs).

3. Prioritize by impact

Rank edge cases based on likelihood and severity, focusing on those that could cause failures or performance issues in production.

4. Explain handling strategy

For each prioritized edge case, describe how your solution detects and handles it, including any trade-offs.

5. Validate with tests

Mention how you would test these edge cases, such as unit tests or property-based testing, to ensure robustness.

Key Points to Mention

  • Empty or null inputs (e.g., empty array, null pointer)
  • Boundary values (e.g., minimum/maximum integers, zero, negative numbers)
  • Duplicates and uniqueness constraints
  • Ordering and sorting assumptions (e.g., unsorted input, stability)
  • Large-scale data and performance (e.g., memory limits, time complexity)
  • Concurrency and thread safety (if applicable)

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