mediumMath & GeometryFacebookMicrosoft
Zero-Wave Flooder
A quality inspector zeroes out every row and column that contains a defective cell, using constant extra space.
Given an m×n matrix, if an element is 0, set its entire row and column to 0. Do it in place with O(1) extra space (other than two flags).
Choose approach
1
1
1
1
0
1
1
1
1
1/3
Narrationstep 1 of 3
firstRow=false, firstCol=false. Mark headers.
Variables
firstRow=false
firstCol=false
How to think about it
- Markers reuse existing storage.
- First row/col must be preserved via flags until last.
Edge cases to catch in interview
- No zeros -> unchanged.
- All zeros -> all zeros.
Examples
Example 1
[[0,0,0,0],[0,4,5,0],[0,3,1,0]]{"grid":[[0,1,2,0],[3,4,5,2],[1,3,1,5]]}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed