Polski

Minimum number of rooms

How many conference rooms are needed for all the meetings to take place? A sweep line over time or a heap of end times.

medium · typescript · javascript · python · csharp · java · go · 20 XP

The office is being redesigned and wants to know how many conference rooms it really needs. The calendar shows when meetings took place. A meeting is a half-open interval [start, end): the room frees up exactly at end, so a meeting ending at 10:00 and another starting at 10:00 can use the same room.

Task

Return the minimum number of rooms that fit all meetings (i.e. the largest number of meetings running at the same time). For an empty list – 0. The input must not be modified.

Signatures: minRooms(meetings) (JS/TS), min_rooms(meetings) (Python), Solution.MinRooms (C#, int[][]), Solution.minRooms (Java, int[][]), MinRooms (Go, [][]int).

Examples

meetingsResult
[[0, 30], [5, 10], [15, 20]]2
[[7, 10], [2, 4]]1
[[1, 5], [5, 10]]1 – the second starts when the first ends
[[1, 10], [2, 9], [3, 8], [4, 7]]4
[]0

Constraints

  • 0 ≤ n ≤ 100,000, 0 ≤ start < end ≤ 10⁹.

Expected complexity

O(n log n) time, O(n) memory.