# 542. 01 Matrix

Given an `m x n` binary matrix `mat`, return the distance of the nearest `0` for each cell.

`Input: mat = [[0,0,0],[0,1,0],[0,0,0]]Output: [[0,0,0],[0,1,0],[0,0,0]]`
`Input: mat = [[0,0,0],[0,1,0],[1,1,1]]Output: [[0,0,0],[0,1,0],[1,2,1]]`
• `n == mat[i].length`
• `1 <= m, n <= 104`
• `1 <= m * n <= 104`
• `mat[i][j]` is either `0` or `1`.
• There is at least one `0` in `mat`.

# 994. Rotting Oranges

You are given an `m x n` `grid` where each cell can have one of three values:

• `1` representing a fresh orange, or
• `2` representing a rotten orange.
`Input: grid = [[2,1,1],[1,1,0],[0,1,1]]Output: 4`
`Input: grid = [[2,1,1],[0,1,1],[1,0,1]]Output: -1Explanation: The orange in the bottom left corner (row 2, column 0) is never rotten, because rotting only happens 4-directionally.`
`Input: grid = [[0,2]]Output: 0Explanation: Since there are already no fresh oranges at minute 0, the answer is just 0.`
• `n == grid[i].length`
• `1 <= m, n <= 10`
• `grid[i][j]` is `0`, `1`, or `2`.

--

--

## More from Joo Hee Paige Kim

Consistency achieves everything https://github.com/paigekim29

Love podcasts or audiobooks? Learn on the go with our new app.