Back to problems

Minimum Moves to Capture the King

Algorithm · Amazon · Medium

A single piece sits somewhere on a two-dimensional board, and the opponent's king sits somewhere else. Each turn the piece may advance exactly one cell in any of eight directions: up, down, left, right, or along one of the four diagonals. Compute the fewest moves the piece needs to land on the king's cell, or return -1 if there is no way to get there. Supplementary assumptions: the original post leaves the board format, the treatment of obstacles and the input sizes…

Loading the rest of the question…