AceYourInterviews
Checking sign-in…

39. Meeting Rooms II — Resource Count

IntermediateActive-end heap and peak concurrency

Assign every meeting to a room so that no two meetings occupying the same room overlap. Return the smallest number of rooms that makes a complete assignment possible.

Rooms are interchangeable, and a room can be reused as soon as its previous meeting ends. Simultaneous demand determines how many rooms are needed.

Example 1

Input

[[0,30],[5,10],[15,20]]

Output

2

Explanation: The long meeting overlaps each short one, but the two short meetings can reuse one room.

Example 2

Input

[[0,3],[0,3],[3,5],[3,5]]

Output

2

Explanation: Both rooms release at three before the two new meetings begin.

Constraints

  • 0 <= meetings.length <= 105
  • meetings[i].length == 2
  • -231 <= start < end <= 231 - 1
Hints
Hint 1

What quantity lower-bounds the number of rooms at an instant?

Hint 2

Which old meetings have ended before the next arrival?

Hint 3

Expire all end≤start, add the new end, and record peak heap size.

Practice on LeetCode ↗ · Premium
Code
Saved on this deviceLn 1, Col 1

A released short meeting lets a room be reused

[[0,30],[5,10],[15,20],[30,40]]
2