Example 1
- Input
- intervals = [[0,30],[5,10],[15,20]]
- Output
- false
Meetings [0,30] and [5,10] overlap since 5 < 30, so one person cannot attend both.
You are given a list of meeting time intervals and must decide whether a single person can attend all of them. Return true only when no two meetings overlap.
Given an array intervals where intervals[i] = [start_i, end_i] is a meeting, determine whether one person can attend every meeting.
Two meetings overlap when each starts before the other ends; meetings that merely touch, like [1,2] and [2,3], do not conflict. Return true if all meetings can be attended and false otherwise.
0 <= intervals.length <= 10^4intervals[i].length == 20 <= start_i < end_i <= 10^6Meetings [0,30] and [5,10] overlap since 5 < 30, so one person cannot attend both.
No two meetings overlap, so one person can attend all of them.
There are no meetings and therefore no conflicting pair. The empty schedule is attendable.
In chronological order the meetings are [0,1], [1,2], [2,3]. Each starts exactly when the previous one ends, so a person can attend all three.
The first two meetings touch without conflict, but the later-listed [2,3] lies inside [0,10]. Checking only original-order neighbors would miss that conflicting pair.
A person can attend all meetings only if no two occupy time simultaneously. Ending one meeting exactly when the next starts is allowed. Example 1 fails because the long meeting [0,30] contains [5,10]. Testing all pairs detects that directly; ordering meetings by start lets us certify the schedule by checking adjacent meetings only.
Reveal Brute Force: intuition, complexity, and code
[a,b] and [c,d] overlap exactly when a < d and c < b.true, since nothing can conflict.[1,2] and [2,3] do not overlap and return true.[1,5] twice overlap and return false.<= in the overlap test, so back-to-back meetings are wrongly flagged as conflicts.When passing every adjacent check in start-time order proves every pair is disjoint, sorting turns an all-pairs conflict search into one neighbor scan.