Given an m×n matrix, if a cell is 0 set its entire row and column to 0, in place. The catch: use O(1) extra space, not O(m+n) marker arrays.
Avoiding the naive extra row/column marker arrays by reusing the matrix's own first row and column as the marker storage.
The trap is that zeroing as you scan corrupts data you still need to read, so beginners allocate rows[] and cols[] boolean arrays (O(m+n)). The O(1) trick reuses the first row and first column as those marker arrays: first record separately whether row 0 and column 0 themselves contain a zero; then for every inner cell (i,j) that is 0, stamp matrix[i][0]=0 and matrix[0][j]=0. In a second pass, zero any inner cell whose row-marker or column-marker is 0. Finally, using the two flags saved at the start, zero the first row and/or first column if needed. Recognition signal: an in-place matrix pass where writes would clobber future reads → carve the marker state out of the structure itself (here the borders) and order the passes so all reads precede the writes. O(m·n) time, O(1) space.
In-place matrix mutation where the marks you need would be overwritten by the mutation → repurpose a border row/column as the marker store and sequence the passes so reads come before writes.
Time O(m·n) · Space O(1)