My first instinct was plain BFS and I actually started coding it before remembering the conversion mechanic.
Use 0-1 BFS on a state graph where each state is (row, col, used_conversion). Treat moving to a passable cell as cost 0 and moving to a blocked cell as cost 1, but only if the conversion hasn't been used. The answer is the minimum cost to reach the bottom-right cell with either 0 or 1 conversions used.
Pro tip: Emphasize that 0-1 BFS with a deque is optimal for this problem because edge weights are only 0 or 1, giving O(mn) time, which is better than Dijkstra's O(mn log(mn)). Also, clarify that the conversion can be used at most once, and the state space naturally enforces that.
Confirm that you can convert at most one blocked cell (0 to 1) during the journey, and that you need the minimum number of steps (moves) from (0,0) to (m-1,n-1). Ask about edge cases like start or end being blocked.
Model each state as (row, col, used) where used is 0 or 1 indicating whether the conversion has been used. This captures all necessary information for the shortest path.
Use 0-1 BFS with a deque: moving to a passable cell has cost 0 (push front), moving to a blocked cell has cost 1 (push back) only if used=0. This efficiently computes the shortest path in O(mn) time.
If the start or end is blocked and cannot be converted (e.g., start is blocked and you have no conversion left), return -1. Otherwise, return the minimum distance to (m-1,n-1,0) or (m-1,n-1,1).
State that time and space are O(mn). Walk through a small example to verify correctness, including cases where conversion is needed and where it's impossible.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.