# Rotting Oranges Multi-Source BFS (Practice 5065): Notes
Interviewers use this pattern to test whether you can state the invariant before coding. Here is a compact rehearsal note.
## Approach
Push every rotten orange at minute 0, BFS level by level, and check that no fresh orange remains.
```python
from collections import deque
def oranges_rotting(g):
q=deque();fresh=0
for r,row in enumerate(g):
for c,v in enumerate(row):
if v==2: q.append((r,c))
elif v==1: fresh+=1
t=0
while q and fresh:
for _ in range(len(q)):
r,c=q.popleft()
for x,y in((r+1,c),(r-1,c),(r,c+1),(r,c-1)):
if 0<=x
g[x][y]=2;fresh-=1;q.append((x,y))
t+=1
return -1 if fresh else t
```
## Complexity
Linear in the dominant input size for the scan; heap/tree variants add a log factor.
## Interview pitfalls
State the invariant out loud, name the complexity, then code. Skipping the invariant is the usual fail mode.
## Practicing out loud
Narrate the approach, complexity and one edge case in under a minute. Disclosure: I work on Linkjob AI, a real-time interview assistant. If you want live practice help, see AI coding interview assistant.