Meetings are held in a set of identical rooms. Each meeting needs one room for its whole duration, and a room can host only one meeting at a time. Return the minimum number of rooms needed to host every meeting.
Function Signature
def min_meeting_rooms(meetings: list[list[int]]) -> int:
Rules
-
meetings[i] = [start, end]
occupies a room for the half-open interval
[start, end)
: the meeting is in progress at every time
t
with
start <= t < end
.
-
A room freed at time
t
can host another meeting that starts at time
t
.
-
Identical meetings listed twice are separate meetings, and each needs its own room.
-
Return
0
when there are no meetings.
Constraints
-
0 <= len(meetings) <= 10^5
-
0 <= start < end <= 10^9
for every meeting
-
Times are integers, so every value fits in a 32-bit signed integer.
-
meetings
is in no particular order.
Examples
Example 1
Input: meetings = [[0, 6], [2, 4], [3, 8], [7, 9]]
Output: 3
At time 3, the meetings [0, 6), [2, 4) and [3, 8) are all in progress, so at least three rooms are needed. Three are enough: one room hosts [0, 6) and then [7, 9), and the other two host [2, 4) and [3, 8).
Example 2
Input: meetings = [[1, 5], [5, 8], [8, 10]]
Output: 1
Each meeting starts exactly when the previous one ends, so one room hosts all three in turn.
Example 3
Input: meetings = [[4, 9], [4, 9], [1, 3]]
Output: 2
The two copies of [4, 9) need separate rooms. The meeting [1, 3) ends before either starts, so it can use one of those two rooms.