You are given a list of meetings, each with a start time and an end time. Every meeting must be held in a room, and a room can host only one meeting at a time. Return the smallest number of rooms that lets every meeting take place at its scheduled time.
A meeting [start, end] occupies its room over the half-open interval from start up to, but not including, end. A meeting that ends at time t and another that starts at time t can therefore use the same room.
Function Signature
def min_rooms(meetings: list[list[int]]) -> int:
Rules
-
meetings[i] = [start_i, end_i]
describes meeting
i
.
-
Two meetings conflict exactly when their half-open intervals overlap, that is, when
start_a < end_b
and
start_b < end_a
.
-
Meetings may be given in any order. Identical meetings may appear more than once, and each copy needs its own room.
-
An empty list needs
0
rooms.
-
The answer is a single integer, so it is unique.
Constraints
-
0 <= len(meetings) <= 10^5
-
0 <= start_i < end_i <= 10^9
-
All values fit in a 32-bit signed integer.
Examples
Example 1
Input: meetings = [[9, 12], [10, 11], [11, 13], [10, 14]]
Output: 3
Explanation: during [10, 11) three meetings run at once: [9, 12], [10, 11] and [10, 14]. When [10, 11] ends at time 11, [11, 13] can take over its room, so no moment ever needs a fourth room.
Example 2
Input: meetings = [[4, 7], [7, 9], [1, 4]]
Output: 1
Explanation: the meetings run back to back, and each starts exactly when the previous one ends, so a single room is enough.
Example 3
Input: meetings = []
Output: 0