def _combine_ind_ranges(ind_ranges_to_merge):
    """
    Utility function for subdivide

    Function that combines overlapping integer ranges.
    Example
    [[1,2,3], [2,3], [3], [4,5], [5]] -> [[1,2,3], [4,5]]
    """
    ind_ranges_to_merge = sorted(ind_ranges_to_merge)
    stack = []
    result = []
    for curr in ind_ranges_to_merge:
        if len(stack) == 0:
            stack.append(curr)
        elif stack[-1][-1] >= curr[0]:
            prev = stack.pop()
            merged = sorted(list(set(prev + curr)))
            stack.append(merged)
        else:
            prev = stack.pop()
            result.append(prev)
            stack.append(curr)
    result += stack
    return result