Model the grid as a graph and use multi-source BFS starting from all initially rotten oranges simultaneously. Track the time (BFS level) and count fresh oranges; if any remain after BFS, return -1, otherwise return the time.
Pro tip: Clarify edge cases upfront (empty grid, no fresh oranges, no rotten oranges) and mention that BFS naturally handles simultaneous rotting, which is more efficient than simulating minute-by-minute.
Confirm grid dimensions, movement directions (4-directional), and what constitutes a minute. Ask about edge cases like empty grid or no fresh oranges.
Recognize this as a shortest-path problem on an unweighted grid, best solved with multi-source BFS from all rotten oranges.
Initialize a queue with all rotten oranges and count fresh ones. Process level by level, rotting adjacent fresh oranges and enqueueing them, incrementing time each level.
After BFS, if any fresh oranges remain, return -1; otherwise return the total minutes elapsed (BFS depth).
State time and space complexity (O(m*n)), and walk through a small example to verify correctness.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.