Given an array of meeting time intervals, determine whether one person could attend every meeting — i.e. whether any two intervals overlap.
Example
Input intervals = [[0,30],[5,10],[15,20]]
Output false
Key Pointers
If any two meetings overlap, one person can't attend both — sorting by start time makes those overlaps easy to spot.
After sorting, only neighboring intervals ever need comparing — the same reasoning as Merge Intervals.
An overlap is exactly when the next meeting starts before the current one ends.
Step-by-Step Analysis
Sort the intervals by start time.
Walk adjacent pairs and check whether the next interval's start is before the current interval's end.
If any pair overlaps, return False.
If the walk finishes with no overlaps, return True.
Complexity
Time: O(n log n) for the sort — Space: O(1) extra
Code
def canAttendMeetings(intervals: list[list[int]]) -> bool:
intervals.sort(key=lambda x: x[0])
for i in range(1, len(intervals)):
if intervals[i][0] < intervals[i - 1][1]:
return False
return True
Code Explanation
How the solution above works, piece by piece.
Sort meetings by start time.
If any meeting starts before the previous one ends, they overlap → False.
Only neighbours need checking: if an earlier meeting ran into meeting i, it would also overlap meeting i − 1 (which starts between them), and that pair was already checked.
No clashes → True.
O(n log n) for the sort.
Visual Walkthrough
Running it on intervals = [[0, 30], [5, 10], [15, 20]]:
After sorting by start, it's enough to compare each meeting with the one just before it. [5, 10] starts at 5, before [0, 30] ends at 30, so one person can't attend both → False.