find the index of values that satisfy A + B =C + D
<p>Working on below problem, using Python 2.7. Post my code and wondering if any further smart ideas to make it run faster? I thought there might be some ideas which sort the list first, and leveraging sorting behavior, but cannot figure out so far. My code is <code>O(n^2)</code> time complexity.</p>

<p><strong>Problem</strong>,</p>

<p>Given an array A of integers, find the index of values that satisfy A + B =C + D, where A,B,C &amp; D are integers values in the array. Find all combinations of quadruples.</p>

<p><strong>Code</strong>,</p>

<pre><code>from collections import defaultdict

sumIndex = defaultdict(list)

def buildIndex(numbers):
    for i in range(len(numbers)):
        for j in range(i+1,len(numbers)):
            sumIndex[numbers[i]+numbers[j]].append((i,j))

def checkResult():
    for k,v in sumIndex.items():
        if len(v) &gt; 1:
            for i in v:
                print k, i

if __name__ == "__main__":
    buildIndex([1,2,3,4])
    checkResult()
</code></pre>

<p><strong>Output</strong>, which is sum value, and indexes which sum could result in such value,</p>

<pre><code>5 (0,3)
5 (1,2)
</code></pre>

<p>Consider the case where all the elements of the array are equal. Then we know the answer beforehand but merely printing the result will take <code>O(n^2)</code> time since there are <code>n*(n-1)/2</code> number of such pairs. So I think it is safe to say that there is no approach with a better complexity than <code>O(n^2)</code> for this problem.</p>

python algorithm python-2.7