Practice/Amazon/Leetcode 782. Transform to Chessboard
CodingMust
You are given an n × n binary grid containing only 0s and 1s. Your task is to determine if you can transform this grid into a valid chessboard pattern by swapping entire rows or entire columns (you can perform any number of swaps). A valid chessboard pattern alternates between 0 and 1 in both horizontal and vertical directions.
If transformation is possible, return the minimum number of swaps required. If it's impossible to create a chessboard pattern, return -1.
For example, these are valid chessboard patterns:
Example 1:
` Input: board = [[0,1,1,0],[0,1,1,0],[1,0,0,1],[1,0,0,1]] Output: 2 Explanation: One way to transform the board is:
Example 2:
Input: board = [[0,1],[1,0]] Output: 0 Explanation: The board is already a valid chessboard pattern
Example 3:
Input: board = [[1,0],[1,0]] Output: -1 Explanation: No matter how we swap rows or columns, we cannot create a chessboard pattern