← Snapchat Interview Insights

Snapchat·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Snapchat SWE interview with a grid pathfinding problem. Pretty standard stuff if you've done BFS before, but they wanted the full complexity breakdown too which tripped me up a little.

Questions Asked (1)

Q1

Given an m x n grid where 0 is passable and 1 is blocked, and you can move in 4 directions, find the shortest path (in number of moves) from a start cell to a target cell. Return -1 if no path exists. Walk through your algorithm and give the time and space complexity.

Algorithms & Data Structures
Author's notes

BFS was the right call and I knew it immediately, but I fumbled the complexity explanation.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use BFS from the start cell, exploring all four directions level by level, because BFS guarantees the shortest path in an unweighted grid. Track visited cells to avoid cycles, and return the distance when the target is reached, or -1 if the queue empties.

Pro tip: Mention that you can optimize space by using a 2D array of distances or by modifying the grid in-place to mark visited cells, but clarify that modifying input may not be allowed. Also, discuss early termination when the target is found.

1. Clarify and Validate Input

Confirm grid dimensions, start and target coordinates, and that start and target are within bounds and not blocked. If invalid, return -1 immediately.

2. Initialize BFS Data Structures

Use a queue for BFS, starting with the start cell. Maintain a visited set or a distance grid to track visited cells and distances.

3. Perform BFS Level by Level

While the queue is not empty, dequeue a cell, check if it's the target, and if not, enqueue all valid unvisited neighbors (up, down, left, right) with distance+1.

4. Handle Target Found or Exhaustion

If target is reached, return the distance. If queue empties without reaching target, return -1.

5. Analyze Complexity

Time complexity is O(m*n) since each cell is visited at most once. Space complexity is O(m*n) for the queue and visited set in the worst case.

Key Points to Mention

  • BFS guarantees shortest path in unweighted graphs
  • Use a queue for level-order traversal
  • Track visited cells to avoid infinite loops
  • Check boundaries and obstacles before enqueueing neighbors
  • Early termination when target is found
  • Time and space complexity: O(m*n)

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