Solution: Set Matrix Zeroes
Explore an optimized approach to solve the Set Matrix Zeroes problem by modifying the matrix in place. Learn to use the first row and column as markers to track zero elements, minimizing space complexity while ensuring all required rows and columns are set to zero. This lesson teaches you how to balance time and space efficiency when working with matrix transformations.
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