Practice Minimum Number of Flips to Convert Binary Matrix to Zero Matrix
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Minimum Number of Flips to Convert Binary Matrix to Zero Matrix
Problem Statement
Given a 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 to 0 and 0 to 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 0 or 1 only. A zero matrix is a matrix with all cells equal to 0.
Source: Minimum Number of Flips to Convert Binary Matrix to Zero Matrix on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
mat = [[0,0],[0,1]]
3
# Example 2
mat = [[0]]
0
# Example 3
mat = [[1,0,0],[1,0,0]]
-1
Constraints
Related LeetCode Problems
Practice more problems similar to Minimum Number of Flips to Convert Binary Matrix to Zero Matrix.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.