[Apologies for multiple posts, I don't see any way to edit a post once made ...] There is also a way to find 2 different numbers instead of just 1 resulting from any of the above variations. If you first do the above xor O(n), your answer is actually A^B since you cannot separate the 2 numbers ... yet. The trick here is to get A and B into different unsorted subarrays, with all the other pairings that self-cancel into either subarray with them (but still in pairs together). That is done by noticing that even though you have no idea what A and B are individually, you do know that since the total is A^B that any 1-bit in the total A^B means that bit is different between A and B. So divide up *all* the numbers based on each having a 0 or 1 in one of those different bits. pseudocode -get the A^B total via the xor O(n) algorithm previously posted -determine as pivot an Nth bit which is different between A and B (any 1-bit in the A^B total) -run through all the same numbers again, but this pass accumulate xor's into an even or odd total depending on the chosen bit - the final answer for A and B will be the 2 accumulated totals Complexity: 2 O(n) which is just O(n)