(knight_row, knight_col), and the pawns stand on the cells listed in pawns, where pawns[i] = [row, column].
Anna and Boris take turns, Anna first. On a turn, the player chooses any remaining pawn, and the knight captures it in the fewest possible moves. On the way the knight may pass over other pawns' cells, but it captures only the chosen one. The chosen pawn does not have to be the nearest.
The game continues while pawns remain. Anna wants the total number of knight moves over the whole game to be as large as possible, Boris wants it as small as possible, and both play perfectly. Return the resulting total number of moves.
A knight moves in an L shape: two cells vertically or horizontally, then one cell at a right angle.knight_row=2, knight_col=2, pawns=[[3, 4]] → 1
There is a single pawn, and the knight takes it in one move: (2, 2) → (3, 4).
knight_row=0, knight_col=0, pawns=[[2, 1], [0, 1]] → 5
If Anna picks the pawn at (0, 1), the knight needs 3 moves to reach it, and then Boris takes (2, 1) in 2 more, 5 in total. If Anna starts with (2, 1) (1 move), Boris is left with (0, 1) in 2 moves, 3 in total. Anna picks the first option.
knight_row=10, knight_col=10, pawns=[[12, 11], [14, 12], [9, 8]] → 5
knight_row=2, knight_col=2, pawns=[[3, 4]]
1
Run checks the first 3 tests in your browser. Submit checks all 92 tests on the server, hidden ones included.