Search⌘ K
AI Features

Solution: Set Matrix Zeroes

Explore how to set entire rows and columns to zero in a matrix if any element is zero, using an optimized in-place algorithm. Learn to track row and column markers with minimal space and understand how to apply this pattern efficiently.

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:

  • 11 \le mat.row, mat.col
...