99. Rotting Oranges (Multi-Source BFS)
MediumGraphs
In a grid, 0 is an empty cell, 1 a fresh orange and 2 a rotten orange. Each minute, every fresh orange next to a rotten one (up, down, left or right) becomes rotten.
Return the number of minutes until no fresh orange remains, or -1 if some orange can never rot.
Example 1
Input: grid = [[2,1,1],[1,1,0],[0,1,1]] Output: 4
Example 2
Input: grid = [[2,1,1],[0,1,1],[1,0,1]] Output: -1
Constraints
1 ≤ rows, cols ≤ 10