An interactive visualization of the interval overlap detection algorithm. Sort meetings by start time, then scan consecutive pairs to check if a person can attend all meetings without conflicts.
Intervals LeetCode 252 ↗ Easyintervals where intervals[i] = [start_i, end_i],
determine if a person could attend all meetings.false if any overlap exists,
and true otherwise.
fun canAttendMeetings(intervals: Array<IntArray>): Boolean { intervals.sortBy { it[0] } for (i in 1 until intervals.size) { if (intervals[i][0] < intervals[i - 1][1]) { return false // overlap found } } return true}
If meetings are sorted by start time, two meetings can only overlap if a meeting starts before the previous one ends. After sorting, a single pass comparing consecutive pairs is enough to detect any conflict.
i from 1 to n-1,
check if intervals[i][0] < intervals[i-1][1].False.True.
Once sorted by start time, overlaps can only occur between adjacent intervals.
If interval A ends before interval B starts (and B
starts before C), then A also ends before C starts.
So we never need to compare non-adjacent pairs.
Sorting takes O(n log n) and the single-pass scan takes O(n),
giving O(n log n) overall. The sort is in-place (or uses O(log n)
stack space), so auxiliary space is O(1).