← Meta Interview Insights

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

Senior
May 2026

Summary

Meta SWE coding round with a maze pathfinding problem that had a twist I did not see coming. The bomb mechanic made it way more interesting than a standard BFS grid question.

Questions Asked (1)

Q1

Given a grid maze with start, end, wall, empty, and bomb cells, find the shortest path from start to end using 4-directional movement. Stepping on a bomb destroys all walls within Manhattan distance 2 from it. Return the minimum steps or -1 if unreachable.

Algorithms & Data Structures
Author's notes

My first instinct was plain BFS and I started coding it before really thinking about state.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a shortest path search on a state space that includes the set of walls destroyed so far. Since bombs can be triggered in any order, use BFS over states (position, bomb_mask) where bomb_mask tracks which bombs have been used, and precompute the effect of each bomb on walls. The answer is the minimum steps to reach the end over all states.

Pro tip: Clarify with the interviewer whether stepping on a bomb is optional or mandatory, and whether bombs can be reused; these details drastically change the solution. Also, mention that if the number of bombs is large, you might need a different approach like Dijkstra with a heuristic, but for typical constraints BFS with bitmask is expected.

1. Clarify problem constraints and rules

Ask about grid size, number of bombs, whether stepping on a bomb is optional, if bombs can be reused, and if walls are permanently destroyed. Confirm movement is 4-directional and cost per step is 1.

2. Define state representation

Represent state as (row, col, bomb_mask) where bomb_mask is a bitmask of bombs already triggered. This captures which walls are currently destroyed because each bomb's effect is deterministic.

3. Precompute bomb effects

For each bomb, precompute the set of walls it destroys (Manhattan distance ≤ 2). Store as a bitmask or list of wall coordinates to quickly check if a cell is passable given the current bomb_mask.

4. Run BFS over states

Start BFS from (start, 0). For each state, explore 4 neighbors. If neighbor is a wall, it's passable only if destroyed by any triggered bomb. If neighbor is a bomb, you may choose to trigger it (updating bomb_mask) or not, depending on rules. Track visited states to avoid cycles.

5. Return minimum steps or -1

During BFS, if you reach the end cell, return the current distance. If BFS exhausts all reachable states without reaching end, return -1.

Key Points to Mention

  • State space includes bomb_mask to track which bombs have been used, enabling correct wall destruction.
  • BFS is optimal for unweighted shortest path; each move costs 1.
  • Precomputing bomb effects avoids recalculating wall destruction on the fly.
  • Visited set must include bomb_mask to avoid revisiting same position with different bomb states.
  • Time complexity: O(R * C * 2^B) where B is number of bombs; space similar.
  • Edge cases: start or end on a wall (impossible), no bombs, bombs that destroy no walls, unreachable end.

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