Rotting Oranges (LeetCode 994).
Asked in the Round 1 stage. Reported follow-up: optimize the solution without using a separate visited array.
Implement def oranges_rotting(grid):. The input is a non-empty rectangular list of lists containing 0 for an empty cell, 1 for a fresh orange, or 2 for a rotten orange. Each minute, every rotten orange infects adjacent fresh oranges in the four cardinal directions. Return the minimum number of minutes required for all fresh oranges to rot, or -1 if some fresh orange can never be reached. The input grid may be modified in place.
def oranges_rotting(grid):