BFS was the obvious move here (pun intended).
Model the chessboard as a graph where each cell is a node and knight moves are edges, then use BFS to find the shortest path from start to target. Since all moves have equal weight, BFS guarantees the minimum number of moves, and we can return -1 if the target is never reached.
Pro tip: Precompute the 8 knight move offsets and use a visited matrix to avoid revisiting cells, which keeps the solution O(N^2) and prevents infinite loops. Also, early return if start equals target (0 moves) or if either is blocked (immediate -1).
Confirm the board size, blocked cells representation, and start/target coordinates. Check edge cases: start or target blocked, start equals target, or out-of-bounds.
Treat each unblocked cell as a node and knight moves as edges. Explain that BFS is ideal because all edges have unit weight, ensuring the shortest path in moves.
Use a queue to process cells level by level, tracking distance. Mark cells as visited when enqueued to avoid duplicates. For each cell, generate all 8 knight moves, filter out invalid or blocked cells.
If target is reached, return the distance; if queue empties, return -1. State time and space complexity: O(N^2) since each cell is visited at most once.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.