A person has a list of meetings, each with a start time and an end time. Return whether they can attend every meeting, which is possible exactly when no two meetings overlap.
Function Signature
def can_attend_all(meetings: list[list[int]]) -> bool:
Rules
-
meetings[i] = [start, end]
occupies the half-open interval
[start, end)
: the meeting is in progress at every time
t
with
start <= t < end
.
-
Two meetings overlap when some time
t
lies in both intervals. A meeting that ends at
t
and a meeting that starts at
t
do not overlap.
-
Identical meetings listed twice are separate meetings, and they overlap each other.
-
Return
True
when there are zero meetings or one meeting.
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 = [[9, 12], [1, 4], [4, 9]]
Output: True
In time order the meetings are [1, 4), [4, 9) and [9, 12). Each one starts exactly when the previous one ends, so none overlap.
Example 2
Input: meetings = [[2, 7], [8, 10], [6, 9]]
Output: False
At time 6, both [2, 7) and [6, 9) are in progress.
Example 3
Input: meetings = [[3, 5], [3, 5]]
Output: False
The two copies of [3, 5) are both in progress at time 3.