Blank Out Every Row and Column Touching a Corrupted Pixel

Last updated: November 29, 2026

Quick Overview

Given an R x C matrix, if any cell is 0, set its entire row and column to 0. Do it in place using constant extra space.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given an R x C matrix, if any cell is 0, set its entire row and column to 0. Do it in place using constant extra space.

A Meta technical screen question that starts with an easy O(R + C) memory version and pushes toward O(1). Framed as invalidating rows and columns of an image tile after a corrupted pixel. The interviewer is checking whether you can reuse the matrix itself for markers without destroying information.

What the Interviewer Expects
  • Give the O(R + C) solution with row and column flag arrays first
  • Move the flags into the first row and column
  • Record separately whether the first row and column contained zeros
  • Apply markers in the right order so they are not overwritten early
  • Test with zeros in the first row and first column
Key Topics to Cover
In-place algorithms
Matrix manipulation
Marker reuse
Space optimization
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Why must the first row and column be handled last?
  • Can you do it with a single extra boolean?
  • How would you parallelize this over a huge matrix?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Matrix up to 200 x 200 of integers.
  • Every 0 in the original matrix zeroes its row and column.
  • O(1) extra space....
High-Level Design

We need to know which rows and which columns contain a zero. Instead of two arrays, store a 0 marker in m[r][0] and m[0][c]. Those cells are also data, so first record whether row 0 or column 0 or...


Submit Your Answer
Markdown supported