Problem 3189 · Medium

Minimum Moves to Get a Peaceful Board

Sort the rook rows and columns separately; the i-th rook row goes to row i, and the same for columns.

Open the interactive visualisation