I'm trying to map this problem into a 4-sum problem, and I find the time complexity is always \$O(n^3)\$. Is there a way to optimize time complexity, with constant additional space complexity \$O(1)\$?Any other advice about improvement for time complexity, code bugs or code style advice is appreciated.ProblemGiven an array A of unique integers, find the index of values that  satisfy A + B =C + D, where A,B,C & D are integers values in the  array. Find all combinations of quadruples.def four_sum (numbers, target, start, end, exclude_index_set):    i = start    j = end    result = []    while i < j:        if i in exclude_index_set:            i += 1        elif j in exclude_index_set:            j -= 1        elif numbers[i] + numbers[j] == target:            result.append((numbers[i], numbers[j]))            i += 1            j -= 1        elif numbers[i] + numbers[j] > target:            j -= 1        else:            i += 1    return resultif __name__ == __main__:    numbers = [1,2,3,4]    result = []    for i,v in enumerate(numbers):        for j in range(i+1, len(numbers)):            r = four_sum(numbers, v+numbers[j], i+1, len(numbers)-1, set([i,j]))            if len(r) > 0:                r.append(([numbers[i],numbers[j]]))                result.append(r)    print result
4-sum algorithm optimization
python;algorithm;python 2.7