Solution: Set Matrix Zeroes
Explore the method to modify a matrix by setting entire rows and columns to zero when an element is zero, using an in-place optimized approach. Understand how to track zero elements efficiently with constant extra space and implement this solution for 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