Skip to main content

Grid Region Zero Propagator

easy
MatrixArrayIn Place Mutation
Asked atAmazonMicrosoftGoogleBloomberg

Problem Description

You are given an `m x n` integer matrix `board`. For every cell containing the value `0`, set the entire row and the entire column of that cell to `0`. Perform this modification **in place**.

**Example 1:**
```
Input: board = [[1,2,0],[4,5,6],[7,8,9]]
Output: [[0,0,0],[4,5,0],[7,8,0]]
```

**Example 2:**
```
Input: board = [[1,1,1],[1,0,1],[1,1,1]]
Output: [[1,0,1],[0,0,0],[1,0,1]]
```

Constraints

  • 1 <= m, n <= 200
  • -2^31 <= board[i][j] <= 2^31 - 1
  • m == board.length
  • n == board[0].length

Follow-up

Can you solve this in O(1) extra space without using the first row/column as auxiliary storage?

Hints

Try the problem first. If you get stuck, you can reveal hints one at a time.

Solution

Leaderboard

No entries yet for python.

Be the first — submit an accepted solution.