Gamified challenge · BFS
A knight is trapped on a board strewn with rocks and must reach the target square, jumping in L-shapes: two squares one way and one square to the side. Each board[r] is a row of . (free), # (a rock: the knight can't land there), K (the knight) and T (the target).
Write escape(board) that returns the path as [row, col] squares from K to T with the fewest jumps, or an empty array if the target can't be reached. A knight on [0, 0] with the target on [1, 2] returns [[0, 0], [1, 2]].
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google