Solution: Set Matrix Zeroes
Discover an efficient algorithm to set matrix rows and columns to zero when a zero element is found. Learn to modify the matrix in place without extra memory by using the first row and column as markers. Understand step-by-step implementation and evaluate time and space complexities for this optimization.
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]