The answer is {3,5} because they appear only once and all remaining elements appear twice.
For the above example the xor value is 0110 = 0011 ^ 0101
Let the two unique numbers are x, y. The next problem is how to find x,y from this xor value. Let us denote ith bit is the first set bit in the xor result. We divide all the numbers in the array into two parts. One part containing all the numbers with bit i = 1, and the other part containing all the numbers with bit i = 0;
This partition segregates the numbers such that all the pairs with ith bit 1 goes to one partition and all pairs with ith bit 0. But x and y fall into two different buckets their bit patterns will be different.
Now finding the XOR value of these partitions separately gives us the required result.
In the above example. The XOR value has 1st bit as 1.
{2,2,3} forms one partition and {1,1,4,4,5} forms another partition.
Parition-1 Partion-2
0010 0001
0011 0100
0010 0001
0100
0101
———————
0011(3) 0101(5)
Here is the Java code to do this.