Merge Intervals
Learn Merge Intervals (Arrays, Data Structures & Algorithms) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
Merging Overlapping Intervals Given a list of intervals like [start, end] , merge all that overlap into the minimum set of non-overlapping intervals. Step 1: sort intervals by START time - O(n log n). Without sorting, overlaps can't be detected in one pass. Step 2: scan left to right; if the current interval's start is ≤ the last merged interval's end, merge them (extend the end); otherwise, start a new interval.