← Snapchat Interview Insights

Snapchat·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Snapchat SWE interview with a grid-based pathfinding problem. Pretty classic BFS territory but the multi-source, multi-person angle adds a layer that tripped me up a bit on the complexity analysis.

Questions Asked (1)

Q1

You're given a 2D grid with walls, people, and exits. Can every person reach an exit? If yes, what's the minimum time for all people to escape, where each person moves optimally and time is the max shortest-path distance across all people?

Algorithms & Data Structures
Author's notes

My first instinct was to BFS from each person separately to find their nearest exit, then take the max.

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 adjacent non-wall cells. Use multi-source BFS from all exits to compute the shortest distance from every cell to the nearest exit, then check if all people have finite distances and return the maximum distance as the minimum time for all to escape.

Pro tip: Clarify that people move independently and do not block each other, so the problem reduces to finding the maximum of individual shortest paths. Mention that if people could block, the problem becomes much harder (e.g., multi-agent pathfinding), but here it's a simple BFS.

1. Clarify assumptions and edge cases

Confirm that people can move in four directions, cannot pass through walls, and that multiple people can occupy the same cell. Discuss edge cases like no people, no exits, or unreachable people.

2. Model as a graph and choose BFS

Represent each cell as a node with edges to adjacent non-wall cells. Use BFS because it finds shortest paths in unweighted graphs.

3. Run multi-source BFS from all exits

Initialize a queue with all exit cells at distance 0. BFS outward to compute the shortest distance from each cell to the nearest exit.

4. Check reachability and compute max distance

For each person, check if their distance is finite. If any is infinite, return that not all can escape. Otherwise, the answer is the maximum distance among all people.

5. Analyze complexity and optimize if needed

Time and space are O(R*C) for an R x C grid. If the grid is huge, consider early termination or bidirectional BFS, but multi-source BFS is optimal here.

Key Points to Mention

  • Multi-source BFS from all exits simultaneously to compute shortest distances efficiently.
  • Graph modeling: cells as nodes, adjacent non-wall cells as edges.
  • Time complexity O(R*C) and space complexity O(R*C) for an R x C grid.
  • Handling unreachable people by checking for infinite distances.
  • The answer is the maximum of the shortest distances, not the sum, because people move in parallel.
  • Edge cases: no people (return 0), no exits (return impossible), people already at exits (distance 0).

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