How long until everything rots?
grid is a list of lists where 0 is empty, 1 is a fresh orange and 2 is a rotten
one. Every minute, each rotten orange rots the fresh oranges directly up, down, left and
right of it. Write minutes_to_rot(grid) that returns how many minutes until no fresh
orange remains, or -1 if some fresh orange can never be reached.
minutes_to_rot([[2, 1, 1], [1, 1, 0], [0, 1, 1]]) -> 4
minutes_to_rot([[2, 1, 1], [0, 1, 1], [1, 0, 1]]) -> -1
minutes_to_rot([[0, 2]]) -> 0
The point is to practise BFS from many sources at once: every rotten orange starts in the queue with time 0.
def minutes_to_rot(grid):
...