Rotting Oranges (Multi-source BFS)

Medium · Queue & Deque · about 20 minutes

Asked at Amazon, Microsoft, DoorDash, Google, Toast.

Each cell of grid holds 0 (nothing), 1 (a fresh orange) or 2 (a rotten orange). Rot spreads once per minute: any fresh orange sharing a side with a rotten one turns rotten. How many minutes pass before no fresh orange is left? Return -1 if some orange can never rot.

Related guides