Graph / BFS•Pattern: Multi-Source BFS•Medium

Rotting oranges — minimum time for all to rot (BFS)

Problem Intuition & Objective

Find minimum minutes for all fresh oranges to rot given rotten ones spread each minute.

Time ComplexityO(m×n)
Optimal
Space ComplexityO(m×n)
Memory Bounds
Optimal Algorithmic Approach

Multi-source BFS: enqueue all initial rotten oranges at time 0 and process wave by wave.

Core Invariants & Edge Cases

  • Multi-source BFS starting from all initially rotten oranges simultaneously
  • Track remaining fresh oranges count
  • If fresh count > 0 after BFS, return -1
Previous ProblemClone a graphNext Problem Walls and gates — fill distance to nearest gate

System Design & Architecture Roadmap

Coding interviews are only 50% of the bar. Master High-Level Design, distributed systems, and Object-Oriented LLD.