![]() |
VOOZH | about |
Given an array where every element appears twice except a pair (two elements). Find the elements of this unique pair.
Examples:
Input : 6, 1, 3, 5, 1, 3, 7, 6 Output : 5 7 All elements appear twice except 5 and 7 Input : 1 3 4 1 Output : 3 4
The idea is based on below post.
Find Two Missing Numbers | Set 2 (XOR based solution)
Implementation:
The unique pair is (7, 5)
Time Complexity: O(n)
Auxiliary Space: O(1)