Solution: Set Matrix Zeroes
Explore how to implement an in-place matrix transformation where any zero element causes its entire row and column to be set to zero. This lesson walks you through an optimized approach using the matrix itself to track zeros, improving space efficiency while maintaining clear steps to modify the matrix directly without additional memory allocation.
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 -
mat[i][j]