grid has 0 (empty), 1 (fresh orange) and 2 (rotten orange). Every minute, each fresh orange that is next to a rotten one (up, down, left or right) becomes rotten. Return the number of minutes until no fresh orange is left, or -1 if some fresh orange can never rot. If there is no fresh orange at the start the answer is 0.
For [[2, 1, 1], [1, 1, 0], [0, 1, 1]] the answer is 4.
Example 1
Input:
oranges_rotting([[2, 1, 1], [1, 1, 0], [0, 1, 1]])
Output:
4
Example 2
Input:
oranges_rotting([[2, 1, 1], [0, 1, 1], [1, 0, 1]])
Output:
-1
0 <= rows, cols <= 3000, 1 or 2.No results yet
Run your code to check it against the examples, or submit to run every test.