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 cell has a fresh orange. If this is impossible, return -1.
grid = [[2, 1, 1], [1, 1, 0], [0, 1, 1]]4grid = [[2, 1, 1], [0, 1, 1], [1, 0, 1]]-1grid = [[0, 2]]0m == grid.lengthn == grid[i].length1 <= m, n <= 10grid[i][j] is 0, 1, or 2Expected time complexity: O(m × n)Run your code to see results
Use Cmd+Enter to run