Why it matters

Meeting rooms is common variant. Understanding shapes greedy application.

Advertisement

The architecture

Sort meetings by start.

PQ tracks end times.

Reuse room if earliest end <= start.

Meeting rooms greedySort by startascendingPQ of end timesmin-heapReuse or new roomcompare vs topAlternative: separate arrival + departure events sweeping in sorted order
Meeting rooms.
Advertisement

How it works end to end

Sort O(n log n).

PQ min-heap for room ends.

Reuse when possible; else add.