← Meta Interview Insights

Meta·Software Engineer·Onsite - Coding / Algorithms·Intermediate

Intermediate
Jun 2026

Summary

Meta SWE coding round, grid traversal problem with incremental test cases. Pretty standard BFS stuff but the multi-step structure tripped me up a bit.

Questions Asked (1)

Q1

Given a 2D grid with walls, an empty cells, a start position S and a target T, find the shortest path from S to T using 4-directional movement. Return -1 if no path exists.

Algorithms & Data Structures
Author's notes

BFS was the obvious move and I knew it immediately, but the problem was structured as a series of test cases building on each other, so I kept second-guessing whether my clean solution would hold up for later parts.

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 BFS to find the shortest path in terms of number of steps, since BFS explores level by level. If the target is unreachable, return -1.

Pro tip: Clarify edge cases upfront (e.g., start equals target, empty grid, no path) and mention that BFS is optimal for unweighted grids; this shows attention to detail and algorithmic maturity.

1. Understand the problem

Restate the problem: find the shortest path in a 2D grid with obstacles, moving in 4 directions. Confirm that each move costs 1 and that you need the minimum number of steps.

2. Choose the algorithm

Select BFS because it guarantees the shortest path in an unweighted graph. Explain why DFS or Dijkstra would be less efficient or unnecessary.

3. Outline BFS implementation

Describe using a queue to track cells to visit, a visited set to avoid cycles, and a distance counter or level tracking. Mention checking boundaries and walls before enqueuing neighbors.

4. Handle edge cases and termination

Discuss early exit if start equals target, and returning -1 if the queue empties without reaching the target. Mention handling invalid inputs if necessary.

5. Analyze complexity

State that time complexity is O(R*C) since each cell is visited at most once, and space complexity is O(R*C) for the queue and visited set in the worst case.

Key Points to Mention

  • BFS is optimal for unweighted shortest path problems.
  • Use a queue for level-order traversal and track distance.
  • Mark cells as visited to avoid infinite loops.
  • Check boundaries and walls before adding neighbors.
  • Return -1 if the queue is exhausted without finding the target.
  • Time and space complexity are O(R*C).

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