Problem Statement | |||||||||||||
You are given a rectangular matrix with odd numbers of rows and columns. Each cell of the matrix contains either 0 or 1. In one move, you can select any one row or column of the matrix and replace all 0's with 1's and all 1's with 0's in that row/column. Your aim is to have an even number of 1's in each row and each column. The elements of the String[] matrix correspond to the rows of the matrix. Return the minimal number of moves needed to achieve your aim, or -1 if it's impossible. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
- | matrix will contain between 1 and 49 elements, inclusive. | ||||||||||||
- | Each element of matrix will contain between 1 and 49 characters, inclusive. | ||||||||||||
- | All elements in matrix will contain the same number of characters. | ||||||||||||
- | The number of elements in matrix will be odd. | ||||||||||||
- | The number of characters in each element of matrix will be odd. | ||||||||||||
- | Each character in each element of matrix will be '0' (zero) or '1' (one). | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
| |||||||||||||
3) | |||||||||||||
|