In this post, we are going to discuss leetcode 1284 — Minimum Number of Flips to Convert Binary Matrix to Zero Matrix, which is asked in Google interviews.
Problem Analysis
Given a
m x n
binary matrixmat
. In one step, you can choose one cell and flip it and all the four neighbors of it if they exist (Flip is changing1
to0
and0
to1
). 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.