Practice Transform to Chessboard
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
You are given an n x n binary grid board. In each move, you can swap any two rows with each other, or any two columns with each other. Return the minimum number of moves to transform the board into a chessboard board. If the task is impossible, return -1. A chessboard board is a board where no 0's and no 1's are 4-directionally adjacent.
Source: Transform to Chessboard on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
board = [[0,1,1,0],[0,1,1,0],[1,0,0,1],[1,0,0,1]]
2
# Example 2
board = [[0,1],[1,0]]
0
# Example 3
board = [[1,0],[1,0]]
-1
Constraints
Related LeetCode Problems
Practice more problems similar to Transform to Chessboard.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.