import operator


def extend_overlapping_spans(spans):
    """
    Method to take a list of spans and extend overlapping spans to the longest span

    Args:
        spans (List[tuple]):    A list of span tuples (start, end)

    Returns:
        List[tuple]: A list of span tuples (start, end) with overlapping spans extended to the longest span
    """
    spans = sorted(spans, key=operator.itemgetter(1))
    i = len(spans) - 1
    while i >= 0:
        start, end = spans[i]
        delete = False
        for j in range(i + 1, len(spans)):
            rstart, rend = spans[j]
            if start < rstart < end:
                spans[j][0] = start
                del spans[i]
                delete = True
                break
            elif start >= rstart:
                del spans[i]
                delete = True
                break
        if ~delete:
            i -= 1
    return spans