You are given an m x n grid where each cell can have one of three values:
0 - empty cell1 - fresh orange2 - rotten orangeEvery minute, any fresh orange that is 4-directionally adjacent to a rotten orange becomes rotten.
Return the minimum number of minutes that must elapse until no fresh oranges remain. If it is impossible, return -1.
grid = [ [2, 1, 1], [1, 1, 0], [0, 1, 1] ]
Input: grid above Output: 4 Explanation: The single rotten orange spreads minute by minute until all reachable fresh oranges are rotten after 4 minutes.
grid = [ [2, 1, 1], [0, 1, 1], [1, 0, 1] ]
Input: grid above Output: -1 Explanation: The orange in the bottom-left corner is cut off by empty cells and can never be reached.
Input: grid = [[0, 2]] Output: 0 Explanation: There are no fresh oranges, so no time is needed.
m == grid.lengthn == grid[i].length1 <= m, n <= 10grid[i][j] is 0, 1, or 2grid = [[2,1,1],[1,1,0],[0,1,1]]