DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
medium
Array

Set Matrix Zeroes

**Problem Statement:** Given an `m x n` integer matrix `matrix`, if an element is `0`, set its entire row and column to `0`'s. You must do it in place. **Hint / Expected Approach:** Use first row/col as markers to avoid extra space **Edge Cases to Consider:** - (1) No zeros - (2) All zeros - (3) Zero in first row or column

Examples

Example 1
Input: [[1,1,1],[1,0,1],[1,1,1]]
Output: [[1,0,1],[0,0,0],[1,0,1]]
Example 2
Input: [[0,1,2,0],[3,4,5,2],[1,3,1,5]]
Output: [[0,0,0,0],[0,4,5,0],[0,3,1,0]]
Example 3
Input: [[1]]
Output: [[1]]

Constraints

  • ▪1 <= nums.length <= 10^4
  • ▪-10^9 <= nums[i] <= 10^9
  • ▪Time complexity should be O(n) or O(n log n)

Watch Out For Edge Cases

  • ▪No zeros
  • ▪All zeros
  • ▪Zero in first row or column
Frequently Asked At
GoogleAmazonMicrosoftAdobeFlipkart