Practice · Intervals · 1 of 4

Fewest Meeting Rooms

You are given intervals, the meetings of one day, each [start, end] with start < end. A room holds one meeting at a time. A meeting that ends at time t frees its room for a meeting that starts at t.

Return the smallest number of rooms that can hold every meeting.

Example 1

Input
intervals = [[9, 12], [10, 11], [11, 14], [13, 15]]
Output
2
[9, 12] and [10, 11] overlap, so two rooms. [11, 14] takes the room freed at 11, and [13, 15] the one freed at 12.

Example 2

Input
intervals = [[1, 5], [2, 6], [3, 7]]
Output
3
All three meetings are going on at time 3.

Constraints

  • intervals holds 1 to 10⁴ meetings.
  • 0 ≤ start < end ≤ 10⁶