Set Matrix Zeros

Given an m x n matrix of 0s and 1s, if an element is 0, set its entire row and column to 0.

Do it in place.

Example

Given array A as

1 0 1
1 1 1 
1 1 1

On returning, the array A should be :

0 0 0
1 0 1
1 0 1

Note that this will be evaluated on the extra memory used. Try to minimize the space and time complexity.

Interview Code Editor
Hints
  • Hint 1
  • Solution Approach
  • Complete Solution
9255 successful submissions.
Asked In:
  • Oracle
  • Amazon
Click here to jump start your coding interview preparation