FreeCareerPath
Build the PrimitiveMedium

Merge Intervals

Write `merge_intervals(intervals)` merging all overlapping intervals and returning the result sorted by start. [[1,3],[2,6],[8,10],[15,18]] -> [[1,6],[8,10],[15,18]] Sort by start, then walk: if the next interval starts at or before the current end, extend the end to the larger of the two; otherwise start a new one. Taking the new interval's end rather than the maximum is the bug that breaks on a nested interval.

What to expect: A timer starts when you begin. Edit the starter code, run it against the test suite as many times as you like, then finish when you're done. The reference solution and interviewer follow-up questions unlock only after you finish.

Log in to start this session

Timed sessions and your results for "Merge Intervals" are saved to your account — logging in takes a few seconds.

Merge Intervals — FreeCareerPath