LeetCode 994 Rotting Oranges - Why Naive Fails

The trap

Simulate minute by minute: scan entire grid, mark oranges that should rot, update grid, repeat.

Each minute, you scan mnm \cdot n cells. With up to mnm \cdot n oranges, worst case O((mn)2)O((m \cdot n)^2).

Can you avoid rescanning the entire grid each minute?