← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026Remote

Summary

Meta SWE coding round, just one algorithm problem the whole session. Pretty standard grid traversal stuff but I fumbled some of the edge case thinking out loud.

Questions Asked (1)

Q1

Given an n x n grid where cells are either open or blocked, find the length of the shortest path from the top-left corner to the bottom-right corner. Return -1 if no path exists.

Algorithms & Data Structures
Author's notes

Knew it was BFS pretty fast, that part wasn't the issue.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the grid as an unweighted graph and use BFS from the top-left cell to compute the shortest path to the bottom-right cell, since BFS guarantees the minimum number of steps. Track visited cells to avoid cycles and return the distance when the target is reached, or -1 if the queue is exhausted.

Pro tip: Clarify upfront whether diagonal moves are allowed and whether the start/end cells can be blocked; handling these edge cases explicitly shows attention to detail and prevents incorrect assumptions.

1. Clarify problem constraints

Confirm movement rules (4-directional vs. 8-directional), whether start/end can be blocked, and the definition of path length (number of steps vs. cells visited).

2. Choose BFS as the algorithm

Explain that BFS is optimal for unweighted shortest path because it explores cells in increasing distance order, guaranteeing the first time we reach the target is the shortest path.

3. Outline BFS implementation

Use a queue initialized with the start cell and a visited set/matrix; for each cell, enqueue valid unvisited neighbors (within bounds, open, not blocked) and track distance.

4. Handle edge cases and termination

Check if start or end is blocked (return -1), and if the queue empties without reaching the target, return -1. Also consider n=1 as a special case.

5. Analyze complexity and optimize

State time and space complexity as O(n^2) since each cell is visited at most once. Mention potential optimizations like bidirectional BFS or A* if the grid is large.

Key Points to Mention

  • BFS guarantees shortest path in unweighted graphs
  • Use a queue for level-order traversal and a visited set to avoid revisiting
  • Check boundaries and blocked cells before enqueuing neighbors
  • Time and space complexity: O(n^2) for an n x n grid
  • Edge cases: start/end blocked, no path exists, 1x1 grid
  • Possible optimizations: bidirectional BFS or A* with Manhattan distance heuristic

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