← Meta Interview Insights

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

Intermediate
May 2026

Summary

Meta SWE coding round, one main problem on grid shortest path. Pretty standard BFS stuff but the follow-ups kept coming and that's where things got interesting.

Questions Asked (1)

Q1

Given a grid maze with walls, a start cell, and a goal cell, find the length of the shortest path moving in four directions through empty cells. Return the number of moves, or -1 if no path exists.

Algorithms & Data Structures
Author's notes

BFS from the start, track distances, return the distance at the goal cell.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the maze as an unweighted graph and use BFS from the start cell to find the shortest path to the goal. Track visited cells to avoid cycles and return the distance when the goal is reached, or -1 if the queue empties.

Pro tip: Mention that BFS is optimal for unweighted grids and that you can optimize space by using a 2D distance array or by marking visited cells in-place if mutation is allowed.

1. Clarify the problem and edge cases

Confirm grid dimensions, wall representation, and whether start/goal are guaranteed to be empty. Discuss edge cases like start equals goal, no path, or invalid inputs.

2. Choose BFS and define state

Explain that BFS is ideal for shortest path in unweighted graphs. Define the state as (row, col) and use a queue to process cells level by level.

3. Outline BFS algorithm

Initialize queue with start, mark visited, and set distance to 0. While queue not empty, dequeue, check if goal, and enqueue valid unvisited neighbors with distance+1.

4. Handle termination and return value

If goal is reached, return its distance. If queue empties without reaching goal, return -1.

5. Analyze complexity and optimizations

State time complexity O(R*C) and space O(R*C). Mention possible optimizations like bidirectional BFS or using a visited set vs. in-place marking.

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 wall conditions before enqueuing
  • Return -1 if the queue is exhausted without finding the goal
  • Time and space complexity are O(R*C) where R and C are grid dimensions

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