m x n binary matrix
mat. In one step, you can choose one cell and flip it and all the four neighbors of it if they exist (Flip is changing
1). A pair of cells are called neighbors if they share one edge.
Return the minimum number of steps required to convert
mat to a zero matrix or
-1 if you cannot.
A binary matrix is a matrix with all cells equal to
A zero matrix is a matrix with all cells equal to
Input: mat = [[0,0],[0,1]] Output: 3 Explanation: One possible solution is to flip (1, 0) then (0, 1) and finally (1, 1) as shown.
Input: mat = [] Output: 0 Explanation: Given matrix is a zero matrix. We don't need to change it.
Input: mat = [[1,1,1],[1,0,1],[0,0,0]] Output: 6
Input: mat = [[1,0,0],[1,0,0]] Output: -1 Explanation: Given matrix can't be a zero matrix
m == mat.length
n == mat[i].length
1 <= m, n <= 3