 <p>if it's only calculating pairs of 2 (and no higher), you can simply count the other two arrays.</p> <p>for anyone in array1, simply <code>count(array2) + count(array3) = number of pairs</code></p>