116. Rotten Spread
mediumbfsmatrixmulti-source bfs
In grid, 0 is empty, 1 is a fresh orange and 2 is a rotten one. Every minute, fresh oranges next to a rotten one (4 directions) rot. Return the minutes until no fresh orange remains, or -1 if that never happens.
Example 1
Inputgrid = [[2,1,1],[1,1,0],[0,1,1]]
Output4
Example 2
Inputgrid = [[2,1,1],[0,1,1],[1,0,1]]
Output-1
Example 3
Inputgrid = [[0,2]]
Output0
Constraints
- 1 ≤ m, n ≤ 10