Greedy Algorithms8 sections · 316 units
Open in Course

Meeting Rooms II - Walkthrough

Tracing the events

Meetings: [[0,30], [5,10], [15,20]]. Events: (00,+1), (55,+1), (1010,-1), (1515,+1), (2020,-1), (3030,-1). Sorted: (00,+1), (55,+1), (1010,-1), (1515,+1), (2020,-1), (3030,-1). Running count: 00 -> 11 -> 22 -> 11 -> 22 -> 11 -> 00. Maximum: 22. So 22 rooms are needed.

The peak happens when meetings [0,30] and [5,10] overlap, and again when [0,30] and [15,20] overlap. The count tracks how many meetings are active at each event time. The maximum count is your answer. This approach simulates the timeline.