Solution: Set Matrix Zeroes
Understand how to identify zeros in a matrix and modify the entire corresponding row and column to zero using minimal extra space. Explore an optimized approach that leverages the matrix's first row and column for tracking to achieve O(m × n) time complexity and O(1) space complexity.
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