Given an array, find the XOR of all values that appear exactly twice.
You are given an integer array nums. Consider only the numbers whose value appears exactly twice in the array. Compute the bitwise XOR of all such numbers and return the result.
If no number appears exactly twice, the answer is 0.
This problem is mainly about counting occurrences and then combining the qualifying values with XOR.
Input Format
- A single integer array
nums. - Each element is an integer.
Output Format
- Return one integer: the XOR of all values that occur exactly twice.
Constraints
1 <= nums.length.- Elements may repeat.
- If no value appears exactly twice, return
0. - Use standard integer XOR semantics.
Example 1
Input
nums = [1, 2, 1, 3, 2, 5]
Output
1
Explanation
The values that appear exactly twice are 1 and 2. Their XOR is 1 ^ 2 = 3. However, if the intended interpretation is to XOR each qualifying occurrence pair value once, the result is 3. If only one qualifying value is expected in a specific variant, adjust accordingly. For this generic formulation, the qualifying values are 1 and 2, so the XOR is 3.
Example 2
Input
nums = [4, 4, 7, 8, 8, 8]
Output
4
Explanation
Only 4 appears exactly twice. Value 8 appears three times, so it is ignored.
Show 1 more example
Example 3
Input
nums = [9, 10, 11]
Output
0
Explanation
No number appears exactly twice.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.