Solution: Set Matrix Zeroes
Understand how to modify a matrix in place by setting entire rows and columns to zero when an element is zero. Explore a space-efficient algorithm that uses the first row and column as markers, eliminating extra memory usage. Learn to implement and analyze the time and space tradeoffs of this classic matrix manipulation problem.
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