My first instinct was plain BFS and I started coding it before really thinking about state.
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.
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.
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.
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.
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.
During BFS, if you reach the end cell, return the current distance. If BFS exhausts all reachable states without reaching end, return -1.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.