backbenchcode
← all problemsnext: Search the Sorted Threshold
#04MediumAlgorithms · 49% acceptance

Merge Overlapping Intervals

SortingIntervalsGreedy

Given a list of intervals `[start, end]`, merge all overlapping intervals and return the minimal set of non-overlapping intervals that covers the same span.

This is exactly the logic behind merging overlapping peaks or genomic features — formalized.

Examples

Input: [[1,3],[2,6],[8,10],[15,18]]

Output: [[1,6],[8,10],[15,18]]

Note: [1,3] and [2,6] overlap and merge into [1,6].

Constraints

Hints

solution.pyPython 3
1
2
3
4
5
6
7
8
9
Test console

// hit Run to execute the sample tests

// Interactive editor preview. Live code execution arrives with your early-access cohort.