Quant Memo
Coding/●●●●●

Minutes until every orange rots (multi-source BFS)

In a grid, 0 is empty, 1 is a fresh orange, and 2 is a rotten orange. Every minute, a fresh orange that is horizontally or vertically adjacent to a rotten one also rots.

grid = [[2, 1, 1],
        [1, 1, 0],
        [0, 1, 1]]
-> 4           # minutes until no fresh orange remains

Return the minutes until no fresh orange is left, or -1 if some fresh orange can never rot.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions