← Meta Interview Insights

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

SeniorPrefer not to say
May 2026

Summary

Meta SWE coding round with a multi-part maze problem that escalated pretty quickly. Five sub-questions on the same grid, ending with a cross-shaped bomb mechanic I hadn't seen before. Felt like a BFS warm-up that slowly turned into something nastier.

Questions Asked (5)

Q1

Given a maze grid where 0 is walkable and 1 is a wall, find the minimum number of steps from a start cell to a target cell moving in four directions. Return -1 if unreachable.

Algorithms & Data Structures
Author's notes

Standard BFS, got it fast.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the maze as a graph and use BFS to find the shortest path because all edges have equal weight. Start from the start cell, explore level by level, and return the distance when the target is reached; if the queue empties, return -1.

Pro tip: Clarify edge cases upfront (e.g., start == target, out-of-bounds, or blocked start/target) and mention that BFS guarantees the shortest path in unweighted grids. Also, discuss space complexity and potential optimizations like bidirectional BFS for large mazes.

1. Clarify problem and edge cases

Confirm grid dimensions, movement rules, and what to return if start or target is invalid or blocked. Discuss edge cases like start equals target.

2. Choose BFS and justify

Explain that BFS is optimal for unweighted shortest path problems. Mention that DFS would not guarantee the shortest path.

3. Outline BFS algorithm

Initialize a queue with the start cell and a visited set. While the queue is not empty, dequeue a cell, check if it's the target, and enqueue all valid unvisited neighbors with distance+1.

4. Analyze complexity and optimizations

State time and space complexity O(rows * cols). Mention potential optimizations like bidirectional BFS or early termination when target is found.

5. Test with examples

Walk through a small example to verify correctness, including a case where the target is unreachable.

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
  • Time and space complexity: O(m*n) where m and n are grid dimensions
  • Edge cases: start == target, blocked start/target, out-of-bounds
  • Potential optimization: bidirectional BFS for large grids

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

Q2

Same maze problem, but now also return one valid shortest path, not just the step count.

Algorithms & Data Structures
Author's notes

Tripped up slightly on the path reconstruction.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use BFS to find the shortest path length, but during traversal, store the predecessor of each visited cell. After reaching the target, backtrack from the target to the start using the predecessor map to reconstruct the path.

Pro tip: Clarify early whether the maze allows diagonal moves and whether the path should be returned as a list of coordinates or directions. Also, mention that BFS guarantees the shortest path in unweighted grids, so no need for Dijkstra.

1. Clarify problem constraints

Ask about movement rules (4-directional vs 8-directional), start/end points, and expected output format for the path.

2. Choose BFS with path tracking

Explain that BFS is optimal for unweighted shortest path. Use a queue for BFS and a separate structure (e.g., dictionary or 2D array) to record each cell's predecessor.

3. Implement BFS and record predecessors

During BFS, when exploring neighbors, if a neighbor is unvisited, mark it visited, set its predecessor to the current cell, and enqueue it.

4. Reconstruct path via backtracking

Once the target is reached, start from the target and follow predecessors back to the start, then reverse the sequence to get the path from start to end.

5. Handle edge cases and complexity

Discuss cases like no path, start equals end, and analyze time/space complexity (O(R*C) for both).

Key Points to Mention

  • BFS guarantees shortest path in unweighted grids.
  • Use a predecessor map (or parent array) to reconstruct the path.
  • Backtracking from target to start yields the path in reverse order.
  • Time and space complexity are O(R*C) where R and C are grid dimensions.
  • Edge cases: no path exists, start equals end, obstacles blocking all routes.
  • Clarify output format: list of coordinates, list of moves, or path length plus path.

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

Q3

Count the total number of distinct shortest paths from start to target in the maze, modulo 1,000,000,007.

Algorithms & Data Structures
Author's notes

This is where I slowed down.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the maze as a graph and use BFS to find the shortest distance from start to all reachable cells. Then, process cells in increasing order of distance, computing the number of shortest paths to each cell by summing the counts from its predecessors that are one step closer. Apply modulo 1,000,000,007 at each addition to prevent overflow.

Pro tip: Clarify the maze representation (e.g., grid with obstacles, 4-directional movement) and whether 'distinct' paths are defined by different sequences of moves. Also, mention that if the graph is unweighted, BFS is optimal; if weighted, Dijkstra's algorithm is needed.

1. Clarify the problem

Ask about the maze structure (grid size, obstacles, movement directions) and confirm that 'shortest paths' means minimum number of steps. Ensure modulo is applied to the final count.

2. Model as a graph

Represent each cell as a node and edges between adjacent passable cells. This abstraction helps in applying standard graph algorithms.

3. Compute shortest distances

Run BFS from the start to compute the shortest distance to every reachable cell. If the target is unreachable, return 0.

4. Count paths in BFS order

Initialize path count to 1 at start. Process cells in increasing distance order; for each neighbor with distance one greater, add the current cell's path count to the neighbor's count modulo 1e9+7.

5. Return result

After processing all cells, the path count at the target is the answer. If target was unreachable, it remains 0.

Key Points to Mention

  • BFS for unweighted shortest paths
  • Dynamic programming on DAG of distances
  • Modulo arithmetic to handle large numbers
  • Handling unreachable target (return 0)
  • Time and space complexity: O(V+E) where V is number of cells and E is number of edges
  • Edge cases: start equals target, obstacles blocking path

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

Q4

Allow breaking through up to k walls while traversing the maze. Find the minimum steps from start to target under this constraint.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

3D BFS with state (row, col, walls_remaining).

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a shortest path search on an expanded state space where each state is (row, col, walls_broken). Use BFS since each move costs 1, and track the minimum steps to reach the target with at most k walls broken. Discuss trade-offs between BFS and other approaches like Dijkstra or A* if costs vary.

Pro tip: Clarify early whether 'breaking a wall' means moving onto a wall cell or destroying it permanently; this affects state definition and visited tracking. Also mention that BFS on the expanded graph is optimal because all edges have unit weight, but if k is large, consider bidirectional BFS or A* with a heuristic to reduce search space.

1. Clarify problem constraints and assumptions

Ask about grid size, movement directions (4 or 8), whether start/target can be walls, and if breaking a wall consumes a step. Confirm that k is an integer and walls are impassable unless broken.

2. Define state and transitions

State = (r, c, w) where w is walls broken so far (0 ≤ w ≤ k). From a cell, move to adjacent non-wall cells with same w, or to wall cells with w+1 if w < k. Each transition costs 1 step.

3. Choose search algorithm

Use BFS because all edges have unit weight. Maintain a 3D visited array or a 2D array storing min walls broken to reach each cell, to avoid revisiting states with more walls broken.

4. Implement and optimize

Use a queue for BFS, track steps as level order. Early exit when target is reached. Discuss optimizations like bidirectional BFS or A* if k is large, and memory trade-offs of 3D visited vs. 2D with min walls.

5. Analyze complexity and edge cases

Time: O(m*n*k) since each cell can be visited with up to k walls broken. Space: O(m*n*k) for visited. Handle cases where target is unreachable even with k walls, or k ≥ number of walls.

Key Points to Mention

  • State space expansion: (row, col, walls_broken) to track remaining breaks.
  • BFS guarantees shortest path because each move costs 1 step.
  • Visited tracking: use 3D boolean array or 2D array storing min walls broken to reach cell.
  • Time and space complexity: O(m*n*k) for both, where m,n are grid dimensions.
  • Trade-offs: BFS vs. Dijkstra (if costs vary) vs. A* (with heuristic) for performance.
  • Edge cases: start or target is a wall, k=0, k >= total walls, unreachable target.

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

Q5

You now have b bombs instead of wall passes. Detonating a bomb at your current cell permanently destroys walls in a full cross shape extending to the grid boundary in all four directions. Find the minimum steps from start to target.

Algorithms & Data StructuresTechnical Trade-offsSystem Design
Author's notes

This one genuinely surprised me.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a shortest path search where the state includes the current cell and the number of bombs remaining. Use BFS with state (row, col, bombs_left), and when moving to an adjacent cell, if it's a wall, you can either detonate a bomb (if bombs_left > 0) to clear a cross shape, or go around. Precompute the effect of detonating a bomb at each cell to quickly check if a wall is destroyed.

Pro tip: Clarify with the interviewer whether bomb detonation is instantaneous and whether the cross destruction is permanent, and discuss the trade-off between BFS with state and A* with a heuristic like Manhattan distance to handle larger grids efficiently.

1. Clarify problem constraints and rules

Ask about grid size, bomb count, whether walls are permanently destroyed, and if detonation counts as a step. Confirm movement rules (4-directional?) and if start/target can be walls.

2. Define state and transitions

State is (r, c, bombs_left). From a cell, you can move to adjacent non-wall cells (cost 1). If adjacent cell is a wall and bombs_left > 0, you can detonate a bomb (cost 1) to clear a cross shape, then move into that cell (cost 1) or stay? Clarify if detonation and move are separate steps.

3. Precompute bomb effects

For each cell, precompute the set of walls destroyed if a bomb is detonated there. This allows O(1) lookup during BFS to check if a wall is cleared.

4. Run BFS with state

Use BFS to find the shortest path from start to target, exploring states in order of steps. Use a visited set to avoid revisiting states. If bombs_left is part of state, the state space is O(R*C*(b+1)).

5. Analyze complexity and optimize

Time complexity O(R*C*(b+1)) for BFS, plus precomputation O(R*C*(R+C)). Discuss potential optimizations like A* with Manhattan distance, or bidirectional BFS if b is small.

Key Points to Mention

  • State space includes bombs remaining, so BFS state is (row, col, bombs_left).
  • Precompute the cross destruction for each cell to avoid recomputation during search.
  • Detonation may count as a step; clarify with interviewer.
  • Use BFS for unweighted shortest path; consider A* for larger grids.
  • Permanent destruction means once a wall is destroyed, it stays destroyed for all subsequent states, but state must track which walls are destroyed? Actually, if bombs are limited, the set of destroyed walls depends on which bombs were used and where. However, if we only care about the current state, we might need to track destroyed walls, which is exponential. But note: detonating a bomb at a cell destroys walls in a cross. If we detonate multiple bombs, the union of destroyed walls matters. This could make state space huge. However, perhaps we can assume that bombs are used independently and we don't need to track all destroyed walls because the path only cares about walls that are currently blocking. But if a wall was destroyed earlier, it remains destroyed, so we need to know which walls are destroyed. This is a critical point: the state must include the set of destroyed walls, which is not feasible for large grids. So we need to rethink: maybe the problem implies that bombs are used at the moment of crossing a wall, and the destruction is permanent but only affects future moves. To avoid tracking all destroyed walls, we can observe that the order of bomb usage matters. However, if we assume that bombs are used only when needed and we don't revisit cells, we might not need to track all destroyed walls? Actually, if we destroy a wall, it could open a shortcut later. So we need to know which walls are destroyed. This suggests that the problem might be NP-hard or require a different approach. Perhaps the intended solution is to treat bomb detonation as an action that clears a cross, and then the grid changes. But with multiple bombs, the state is the set of destroyed walls, which is too large. So maybe the problem expects a simpler interpretation: each bomb can be used to destroy a cross, but the destruction is permanent, and we can use bombs at any time. To find minimum steps, we might need to consider all possible sequences of bomb placements, which is combinatorial. However, for an interview, they might expect a BFS where state includes bombs left and the set of destroyed walls is implicitly handled by the fact that we only detonate bombs when we are at a cell, and we can assume that we never need to detonate a bomb unless it helps. But still, the state space is large. Perhaps the problem is meant to be solved with BFS where state is (r, c, bombs_left) and we assume that walls are only destroyed when we detonate, and we don't need to track which walls are destroyed because we can only detonate at our current cell, and the cross destruction is local. But if we detonate at cell A, it destroys walls in a cross. Later, if we are at cell B, we might benefit from a wall destroyed by the bomb at A. So we need to know that. This is a key point to mention: the state must include the set of destroyed walls, which is exponential, so we need to find a way to avoid that, perhaps by observing that bombs are limited and we can use them in a way that doesn't require tracking all destroyed walls if we assume that we only detonate when necessary and we don't revisit cells? But that's not guaranteed. So the candidate should discuss this trade-off and possibly propose a solution that works for small b or small grid, or use a different approach like Dijkstra on a graph where nodes are (r, c, bombs_left) and edges are moves, but the effect of bombs is not captured. Actually, if we detonate a bomb, it changes the grid, so the graph changes. This is a dynamic graph problem. So the candidate should mention that the problem is more complex than standard BFS and discuss potential approaches like state space search with memoization on the set of destroyed walls, which is infeasible for large grids, so we might need to assume that bombs are used independently and we can precompute the shortest path with a certain number of bombs? Not exactly. So this is a key point to mention: the state space explosion due to permanent wall destruction.
  • Discuss trade-offs between BFS and A* for performance.
  • Consider edge cases: no bombs, bombs more than needed, start or target blocked by walls.

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