Illustration showing rows and columns of a matrix being set to zero

Set Matrix Zeroes (Blind 75): O(1) Space Solution

Problem Overview We are given a matrix of size m * n. If any element in the matrix is 0, set its entire row and column to 0. Constraint: The solution must use O(1) extra space. LeetCode - Set Matrix Zeroes Example Input: matrix = [[1,1,1],[1,0,1],[1,1,1]] Output: [[1,0,1],[0,0,0],[1,0,1]] Brute Force Intuition and Approach Use an unordered_map to store positions of original zeros. In a second traversal: ...

February 20, 2026 · 4 min · 749 words · Hitesh Patel