Merge Intervals
Medium
Question
Given a list of intervals, merge any overlapping intervals and return the updated list. The intervals in the returned list should be sorted by their start values and should be non-overlapping.
Input: [[0, 2], [3, 5], [4, 6]]
Output: [[0, 2], [3, 6]]
Intervals [3, 5] and [4, 6] are overlapping, so they merged to become [3, 6].
Input: [[6, 7], [1, 2], [4, 5]]
Output: [[1, 2], [4, 5], [6, 7]]
There are no overlapping intervals, so no intervals were merged.
Input: [[2, 5]]
Output: [[2, 5]]
Clarify the problem
What are some questions you'd ask an interviewer?
Understand the problem
What is the outcome of this list after its overlapping intervals are merged? [[-5, -2], [-4, -1], [1, 3], [2, 5], [6, 7]]
[[-4, -2], [2, 3]]
[[-2, -4], [2, 3]]
[[-5, -1], [1, 5]]
[[-5, -1], [1, 5], [6, 7]]
All test cases pass! 🎉
Time limit exceeded
InputExpected OutputActual Output
Standard OutputScroll down...
Login or signup to save your code.
Uh oh... looks like you don't yet have access.
Not sure what this unlocks? Check out a free pattern section.