The number without a partner
Reported in interviews at (where)
- To The New
In nums every value appears exactly twice, except one value that appears once. Return that value.
Aim for one pass and O(1) extra memory.
- Input
nums = [6,1,6]- Output
1
6 has its partner; 1 does not.
- Input
nums = [-3,8,8,5,-3]- Output
5
Negative values pair up the same way.
Limits
1 <= nums.length <= 99999nums.length is odd-1000000000 <= nums[i] <= 1000000000every value but one appears exactly twice
Hints
Hint 1
x ^ x is 0 and x ^ 0 is x, in any order. XOR all the values together: every pair cancels out.
Where this was reported
- To The New, MEAN trainee campus interview, 2025 (GeeksforGeeks)
Our own problem on the task these candidates describe; the wording, examples and tests are InternDoor’s.
Run your code to check it on the examples. Submit runs every hidden test.