11
How would you merge overlapping intervals?
Tap to write answer
0 words | 0 charsPress Enter ↵ to reveal
Your Attempt
0 wordsRefined Model Answer
ReferenceI would first sort the intervals by their start time. Then I would scan through them and either merge the current interval with the next one if they overlap, or move on to a new interval if they do not. The reason I choose this approach is that once the intervals are sorted, the merge decision becomes very easy. The time complexity is O(n log n) because of sorting, and the scan itself is O(n). I would also mention edge cases like touching intervals, nested intervals, and already sorted input.