<jupyter_start><jupyter_text>ProblemGiven a list of possibly overlapping intervals, return a new list of intervals where all overlapping intervals have been merged.The input list is not necessarily ordered in any way.For example, given [(1, 3), (5, 8), (4, 10), (20, 25)], you should return [(1, 3), (4, 10), (20, 25)].  SolutionWe can do this by sorting all the intervals by their start time. When looking at the current interval, if it overlaps with the previous one we can just remove it. If the previous<jupyter_code>def merge_overlaps(array):
    if len(array) == 1:
        return array
    array.sort(key=lambda x: x[0])  # O(N log N) sorting
    i = 1
    while i < len(array):
        if is_subset(array[i], array[i - 1]):
            # current is subset of previous, remove current
            del(array[i])
        elif is_subset(array[i - 1], array[i]):
            # previous is subset of current, remove previous
            del(array[i - 1])
        else:
            i += 1
    return array

def is_subset(subset, parent) -> bool:
    return True if parent[0] <= subset[0] and subset[1] <= parent[1] else False

array = [(1, 3), (5, 8), (4, 10), (20, 25)]
merge_overlaps(array)
arr = [(1, 10), (2, 3), (11, 12), (3, 4), (7, 8), (9, 10)]
merge_overlaps(arr)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13210445468509985, 'fraction_numerical': 0.0445468509984639, 'mean_word_length': 3.1629392971246006, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '336693', 'license': 'MIT', 'n_tokens_mistral': 465, 'n_tokens_neox': 412, 'n_words': 168, 'path': 'arrays/overlapping_interval.ipynb', 'repo_name': 'codacy-badger/algorithms-1', 'size': '1302'}