26Merge Intervals

    Hardsortinglists

    Write merge(intervals) that takes a list of [start, end] pairs and merges every group that overlaps, returning the merged pairs sorted by start.

    Intervals that only touch, like [1, 4] and [4, 5], count as overlapping.

    Examples

    Example 1
    >>> merge([[1, 3], [2, 6], [8, 10], [15, 18]])
    [[1, 6], [8, 10], [15, 18]]
    Example 2
    >>> merge([[1, 4], [4, 5]])
    [[1, 5]]

    Run examples checks the 2 examples above. Submit runs all 6 tests, including hidden edge cases, and marks the challenge solved.

    solution.py
    Loading Python…

    Test results show up here

    Write merge in the editor, then run the examples. Use print() freely: its output is shown for each test.