← All problems
Set Matrix Zeroes (O(1) space)
Given an m x n matrix, if any cell is zero, set its entire row and column to zero — using only constant extra space. The first row/column can serve as marker storage with care.
Complexity
Time O(mn), Space O(1)
Common pitfalls
- Zeroing markers prematurely
- Forgetting the two flags
Your solution
Log in to save your code and track progress.