Tap here to switch tabs
Problem
Submissions

Problem: Transform to Chessboard

med
30 min
Try to solve the Transform to Chessboard problem.

Statement

You are given an n×nn \times n binary grid board. In each move, you can swap any two rows or any two columns.

Return the minimum number of moves required to transform the grid into a valid chessboard. If it is impossible to transform the grid into a chessboard, return −1-1.

A valid chessboard is a grid where no two horizontally or vertically adjacent cells contain the same value.

Constraints:

  • n ==== board.length

  • n ==== board[i].length

  • 2≤2 \leq n ≤30\leq 30

  • board[i][j] is either 00 or 11.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Transform to Chessboard

med
30 min
Try to solve the Transform to Chessboard problem.

Statement

You are given an n×nn \times n binary grid board. In each move, you can swap any two rows or any two columns.

Return the minimum number of moves required to transform the grid into a valid chessboard. If it is impossible to transform the grid into a chessboard, return −1-1.

A valid chessboard is a grid where no two horizontally or vertically adjacent cells contain the same value.

Constraints:

  • n ==== board.length

  • n ==== board[i].length

  • 2≤2 \leq n ≤30\leq 30

  • board[i][j] is either 00 or 11.