Merge Overlapping Intervals
Given a list of intervals [start, end], merge all overlapping intervals and return the result sorted by start time. Intervals that touch, such as [1, 4] and [4, 5], overlap.
Hints
Hint 1
Sort by start time first. What invariant does that buy you when you sweep left to right?
Hint 2
An interval overlaps the last merged one exactly when its start is less than or equal to the last merged end.
Topics
Asked at
Sign in to use the assistant — ask what the problem means, get a hint when you're stuck, or have your current work reviewed. Conversations save to your account.