Greedy Algorithms8 sections · 316 units
Open in Course

Meeting Rooms II - Approach 1

Event-based counting

Approach: Treat starts and ends as events. Count running meetings.

1.1. Create events: (time, +1 for start, -1 for end).

2.2. Sort by time. If tie, process end before start (a room freed is reusable).

3.3. Scan events, track running count.

4.4. Answer is maximum count seen. This counts how many meetings are happening simultaneously at each moment. The trick: processing end before start handles back-to-back meetings correctly. If meeting A ends at time 55 and meeting B starts at time 55, they can share a room.