← Meta Interview Insights

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

IntermediatePrefer not to say
May 2026

Summary

Meta SWE coding round, got a grid BFS problem. Pretty standard shortest path stuff but the pressure of it being Meta made me second-guess myself more than I should have.

Questions Asked (1)

Q1

Given a 2D grid with a mouse start position, a cheese position, walls, and open cells, find the minimum number of steps for the mouse to reach the cheese moving in four directions. Return -1 if no path exists.

Algorithms & Data Structures
Author's notes

Classic BFS and I knew it immediately, which almost made it worse because I started overthinking edge cases instead of just writing the code.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Recognize this as a shortest path problem on an unweighted grid and apply BFS from the start position, exploring all four directions while avoiding walls and visited cells. Return the distance when the cheese is reached, or -1 if the queue is exhausted without finding it.

Pro tip: Mention that BFS is optimal for unweighted grids because it explores level by level, guaranteeing the first time you reach the cheese is the shortest path. Also, discuss edge cases like start equals cheese, no path, and large grids to show thoroughness.

1. Clarify the problem and constraints

Confirm grid dimensions, movement rules (4-directional), and what constitutes a wall or open cell. Ask about edge cases like start equals cheese or no path.

2. Choose BFS as the algorithm

Explain that BFS is ideal for finding the shortest path in an unweighted graph, as it explores nodes in increasing order of distance from the start.

3. Outline the BFS implementation

Describe using a queue to store cells and their distances, a visited set to avoid revisiting, and iterating through the four directions for each cell.

4. Handle termination and edge cases

Return the distance when the cheese is dequeued or reached; if the queue empties, return -1. Also handle start equals cheese by returning 0 immediately.

5. Analyze complexity and potential optimizations

State that time and space complexity are O(rows * cols) in the worst case. Mention possible optimizations like bidirectional BFS if needed.

Key Points to Mention

  • BFS guarantees shortest path in unweighted graphs
  • Use a queue for level-order traversal
  • Track visited cells to avoid cycles and redundant work
  • Check boundaries and wall conditions before enqueueing
  • Time and space complexity: O(R*C)
  • Edge cases: start equals cheese, no path, empty grid

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