You are given a list of meetings. Each meeting is a pair [start, end] with start < end. Decide whether one person can attend every meeting, which is possible only when no two meetings overlap.
A meeting that ends exactly when another one begins is not a conflict. For example, [8, 10] and [10, 12] can both be attended.
Function Signature
def can_attend_meetings(intervals: list[list[int]]) -> bool:
Rules
-
Each interval is a list of two integers
[start, end]
. The list is not necessarily sorted.
-
Two meetings
[a, b]
and
[c, d]
conflict when
max(a, c) < min(b, d)
. Meetings that only share an endpoint do not conflict.
-
Return
True
when no pair of meetings conflicts, and
False
otherwise. An empty list or a single meeting returns
True
.
Constraints
-
0 <= len(intervals) <= 10^4
-
0 <= start < end <= 10^4
Examples
Input: intervals = [[1, 40], [15, 25], [35, 45]]
Output: False
[1, 40] overlaps [15, 25] because 15 comes before 40, and it also overlaps [35, 45]. One conflict is enough to make the answer False.
Input: intervals = [[2, 7], [8, 12]]
Output: True
The first meeting ends at 7 and the second starts at 8, so they do not overlap.
Input: intervals = [[10, 12], [8, 10]]
Output: True
The list is out of order. In time order, [8, 10] ends at 10, exactly when [10, 12] starts, and the rules treat that as no conflict.