← All Patterns

Pattern Recognition Drill

#144

Medium Graphs

The Problem

In a grid, fresh oranges rot when adjacent to rotten ones. Find the minimum minutes for all to rot.

What approach would you use?

Think about it before scrolling down.

Rotting Oranges

Key Signals

Queue / BFS

Add all rotten oranges to queue at time 0. BFS spreading rot. Track max time. O(m*n).

Alt: DFS / Recursion

DFS from each rotten orange updating min time — but BFS is cleaner for simultaneous spread.

Common Trap

Don't BFS from one rotten orange at a time — they all spread SIMULTANEOUSLY. Multi-source BFS.

← #143 #145 →