Knew it was BFS pretty fast, that part wasn't the issue.
Model the grid as an unweighted graph and use BFS from the top-left cell to compute the shortest path to the bottom-right cell, since BFS guarantees the minimum number of steps. Track visited cells to avoid cycles and return the distance when the target is reached, or -1 if the queue is exhausted.
Pro tip: Clarify upfront whether diagonal moves are allowed and whether the start/end cells can be blocked; handling these edge cases explicitly shows attention to detail and prevents incorrect assumptions.
Confirm movement rules (4-directional vs. 8-directional), whether start/end can be blocked, and the definition of path length (number of steps vs. cells visited).
Explain that BFS is optimal for unweighted shortest path because it explores cells in increasing distance order, guaranteeing the first time we reach the target is the shortest path.
Use a queue initialized with the start cell and a visited set/matrix; for each cell, enqueue valid unvisited neighbors (within bounds, open, not blocked) and track distance.
Check if start or end is blocked (return -1), and if the queue empties without reaching the target, return -1. Also consider n=1 as a special case.
State time and space complexity as O(n^2) since each cell is visited at most once. Mention potential optimizations like bidirectional BFS or A* if the grid is large.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.