โ† Core Algorithms
#4 most askedVery commonMediumIntervals

Merge Intervals

New to Intervals? Learn it from scratch first
Intervals โ†’
๐Ÿข Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.
I was asked this

Given a list of intervals [start, end], merge all overlapping intervals and return the result sorted by start.

[[1, 3], [2, 6], [8, 10], [15, 18]] โ†’ [[1, 6], [8, 10], [15, 18]]

๐Ÿงช Practice

Write your solution, then press Run tests. Explain your approach out loud as you go.

Python
def merge(intervals):
    pass

Output appears here. Press Run or Ctrl/โŒ˜ + Enter.

Try it first. Struggling for a few minutes is how it sticks.