Tap here to switch tabs
Problem
Submissions

Problem: Minimum Moves to Get a Peaceful Board

med
30 min
Try to solve the Minimum Moves to Get a Peaceful Board problem.

Statement

You are given a 22D integer array rooks of length nn, where rooks[i] = [x_i, y_i] represents the position of the iextthi^{ ext{th}} rook on an nimesnn imes n chessboard.

A chessboard is considered peaceful if each row contains exactly 11 rook and each column contains exactly 11 rook.

In a single move, you can move any rook to an adjacent cell horizontally or vertically.

Return the minimum number of moves required to make the chessboard peaceful.

Constraints:

  • 1≤n==1 \leq n == rooks.length ≤500\leq 500

  • rooks[i].length ==2== 2

  • 0≤xi,yi≤n−10 \leq x_i, y_i \leq n - 1

  • The input is generated such that there are no 22 rooks in the same cell.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Moves to Get a Peaceful Board

med
30 min
Try to solve the Minimum Moves to Get a Peaceful Board problem.

Statement

You are given a 22D integer array rooks of length nn, where rooks[i] = [x_i, y_i] represents the position of the iextthi^{ ext{th}} rook on an nimesnn imes n chessboard.

A chessboard is considered peaceful if each row contains exactly 11 rook and each column contains exactly 11 rook.

In a single move, you can move any rook to an adjacent cell horizontally or vertically.

Return the minimum number of moves required to make the chessboard peaceful.

Constraints:

  • 1≤n==1 \leq n == rooks.length ≤500\leq 500

  • rooks[i].length ==2== 2

  • 0≤xi,yi≤n−10 \leq x_i, y_i \leq n - 1

  • The input is generated such that there are no 22 rooks in the same cell.