Meeting Rooms II

Greedy & Intervals, problem 7 of 8

Meeting Rooms II

Medium

LC #253

intervalsheapsweep line

Not attempted yet

Given meeting times intervals where each is [start, end], return the minimum number of conference rooms needed so that no two meetings share a room at the same time.

A meeting ending at time t frees its room for one starting at t.

(A classic interview question; it's a premium problem on LeetCode.)

Example 1

Input: intervals = [[0,30],[5,10],[15,20]]
Output: 2

[0,30] needs one room; [5,10] and [15,20] can share a second.

Example 2

Input: intervals = [[7,10],[2,4]]
Output: 1

Example 3

Input: intervals = [[1,5],[5,10],[10,15]]
Output: 1

Back-to-back meetings reuse the same room.

Constraints

  • 1 <= intervals.length <= 10^4
  • 0 <= start < end <= 10^6

Python

Loading draft…

Test results

8 tests available

No results yet

Run tests your code against the examples; Submit runs the hidden tests too.

3 examples, 5 hidden

Run examples, then submit all tests.