Greedy Algorithms8 sections · 316 units
Open in Course

Meeting Rooms II - Approach 2

Min-heap method

Alternative: Use a min-heap of end times.

1.1. Sort meetings by start time.

2.2. Use a min-heap to track end times of ongoing meetings.

3.3. For each meeting: if its start >= heap min, pop the heap (reuse that room).

4.4. Push the new meeting's end time.

5.5. Answer is heap size. The heap tracks the earliest-ending ongoing meeting. If a new meeting starts after that, you can reuse the room. The heap size at the end tells you how many rooms you need simultaneously.