Imagine you have an array of integers where exactly two elements appear only once and all other elements appear exactly twice. Your mission is to find these two unique elements!
This problem is a fascinating extension of bit manipulation techniques. While finding one unique number among duplicates is straightforward using XOR, finding two unique numbers requires a clever twist.
The Challenge: You must solve this in O(n) time complexity and O(1) space complexity - no hash tables allowed!
Example: Given [1,2,1,3,2,5], the two unique numbers are 3 and 5.
Input & Output
Visualization
Time & Space Complexity
Single pass through array to XOR all elements, then another pass to separate groups
Only using a few integer variables for XOR operations and bit manipulation
Constraints
- 2 โค nums.length โค 3 ร 104
- -231 โค nums[i] โค 231 - 1
- Each integer appears exactly twice except for two integers
- The two unique integers are guaranteed to be different