Clear Rows and Columns of Failed Excel Cells In Place
Last updated: November 29, 2026
Quick Overview
In a numeric Excel range, any cell equal to 0 marks a failed validation, and its entire row and column must be cleared to 0. Do this in place using O(1) extra memory.
Microsoft
November 29, 20260
0
0 solved
In a numeric Excel range, any cell equal to 0 marks a failed validation, and its entire row and column must be cleared to 0. Do this in place using O(1) extra memory.
This O(1) space matrix problem is common in Microsoft technical screens, framed here around Excel. The interviewer pushes from an O(rows + cols) solution down to using the first row and column as marker storage, and watches for the order of operations bug.
What the Interviewer Expects
- Start with O(rows + cols) marker sets, then reduce space
- Use the first row and first column as markers
- Record separately whether the first row and column originally had a zero
- Apply markers to the interior before clearing the first row and column
- Verify with a zero in the first row or column
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- What if the grid is too large for memory and arrives row by row?
- How would you do this when the cleared value must be a sentinel instead of 0?
- Parallelize the marking pass across threads safely.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: rectangular matrix of integers.
- For every original 0 at (r, c), set all of row r and column c to 0.
- Only original zeros trigger clearing, not zeros we write.
- O(1) extra space....
High-Level Design
The simple approach collects the zero rows and columns in two sets. To avoid that extra space, store the same information in the matrix itself: grid[r][0] = 0 means row r must be cleared, and `grid[...