Skip to content
BytePatterns

Rooms Needed for Every Meeting

MediumIntervals#min-heap#sweep-line#sorting~20m

Problem

Given a list of meetings as (start, end) pairs, return the smallest number of rooms that lets every meeting take place. A meeting occupies its room from start up to but not including end, so a meeting that ends at 10 frees its room for one that starts at 10.

Examples

Input:  meetings = [(0, 30), (5, 10), (15, 20)]
Output: 2
Why:    the long meeting overlaps both short ones, but the short ones never overlap each other
Input:  meetings = [(7, 10), (2, 4)]
Output: 1
Input:  meetings = [(1, 5), (5, 9), (9, 12)]
Output: 1
Why:    edge case, back-to-back meetings share one room because the end time is exclusive

Hints

0 / 3

Stuck on the idea rather than the code? Meeting Rooms covers it.