MEDIUMasked at 24 companies

Set Matrix Zeroes

A medium-tier problem at 61% community acceptance, tagged with Array, Hash Table, Matrix. Reported in interviews at Expedia and 23 others.

Founder's read

Set Matrix Zeroes shows up across 24 companies including Microsoft, Amazon, and Adobe. It's the kind of problem that feels straightforward until you realize the naive approach tanks your space complexity. You need to mark rows and columns as zero without using extra arrays, which means modifying the matrix in place using the matrix itself as storage. If you blank on the trick during your live assessment, StealthCoder surfaces a working solution invisible to the proctor. The acceptance rate is 61%, which means enough candidates stumble here that preparation pays off.

Companies asking
24
Difficulty
MEDIUM
Acceptance
61%

Companies that ask "Set Matrix Zeroes"

If this hits your live OA

Set Matrix Zeroes is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share.

Get StealthCoder
What this means

The trap is reaching for a HashTable or a separate array to track which rows and columns to zero. That burns O(m + n) extra space and screams 'I didn't optimize.' The real solution uses the first row and first column of the matrix as flags, storing whether each row and column should become zero. You need a boolean to track the first row separately since it doubles as storage. Common failure points: forgetting to handle the first row and column last, overwriting values before you've read them, or not tracking whether the first row itself should be zeroed. During a live OA, candidates often code the first approach, then panic trying to refactor under time pressure. StealthCoder hedges that moment by delivering the optimized pattern instantly.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Set Matrix Zeroes recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Set Matrix Zeroes interview FAQ

Is Set Matrix Zeroes asked more often at FAANG than mid-market?+

It appears across both. The top 10 askers include Microsoft, Amazon, and Adobe alongside companies like Expedia and eBay. 61% acceptance rate suggests it's not a hard filter, but appearing at major tech companies means it's worth drilling before your OA.

What's the trick to not using extra space?+

Use the first row and column of the matrix as a lookup table for which rows and columns to zero. Store a boolean separately for the first row itself, since it's doing double duty. Iterate from bottom-right to top-left to avoid overwriting values you still need.

How does this relate to the Hash Table topic tag?+

The naive approach uses a HashTable or set to track rows and columns. The optimized solution replaces that with in-place matrix modification. Understanding why one is better prepares you for follow-up questions about space trade-offs.

Can I just use two separate arrays for rows and columns?+

Technically yes, and it's cleaner to code. But the problem often expects O(1) space, not O(m + n). If the interviewer doesn't push back, that solution works. If they ask you to optimize, you'll need the matrix-as-storage trick.

What's the most common mistake candidates make?+

Overwriting a zero before reading it, or forgetting that the first row needs special handling. Many also iterate left-to-right and top-to-bottom, which corrupts data. Reverse order matters. Practice the iteration order until it's muscle memory.

Want the actual problem statement? View "Set Matrix Zeroes" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.