994. Rotting Oranges
Practice Rotting Oranges for free on NudgeCode: Medium, Graph pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Each cell of grid is 0 (empty), 1 (fresh orange) or 2 (rotten orange). Every minute, each fresh orange that is directly up, down, left or right of a rotten orange becomes rotten. Return the number of minutes until no fresh orange is left, or -1 if some fresh orange can never rot.
Example
grid = [[2,1,1],
[1,1,0],
[0,1,1]] -> 4
Constraints
- 1 <= m, n <= 20 (m rows, n columns)
- grid[i][j] is
0,1or2