Rotting Oranges
In an m x n grid each cell is 0 (empty), 1 (fresh orange), or 2 (rotten orange). Every minute, any fresh orange 4-directionally adjacent to a rotten one becomes rotten. Return the minimum number of minutes until no fresh orange remains, or -1 if some orange can never rot.
Open official problem prompt ↗Find the minimum minutes for rot to reach every fresh orange, or detect that some are unreachable.
Like ink dropped simultaneously into a grid of blotting paper from several spots at once; you count how many seconds pass until the ink has soaked every reachable square.
- Input
- grid = [[2,1,1],[1,1,0],[0,1,1]]
- Output
- 4
- Why
- Rot spreads outward from (0,0); the farthest fresh orange at (2,2) becomes rotten after 4 minutes.
m == grid.lengthn == grid[i].length1 <= m, n <= 10grid[i][j] is 0, 1, or 2