Solution: Set Matrix Zeroes
Explore an efficient method to modify a matrix by setting entire rows and columns to zero when any element is zero. Understand how to use the matrix's first row and column as markers to minimize extra space. This lesson guides you through implementing the optimal approach with linear time complexity and constant space, helping you apply this pattern in coding interviews.
Statement
Given a matrix, mat, if any element within the matrix is zero, set that row and column to zero. The performed operations should be in place, i.e., the given matrix is modified directly without allocating another matrix.
Constraints:
-
mat.row,mat.col