InternDoor

The number without a partner

Easybit manipulation · arrays

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.

Example 1
Input
nums = [6,1,6]
Output
1

6 has its partner; 1 does not.

Example 2
Input
nums = [-3,8,8,5,-3]
Output
5

Negative values pair up the same way.

Limits

  • 1 <= nums.length <= 99999
  • nums.length is odd
  • -1000000000 <= nums[i] <= 1000000000
  • every 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

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.

Ready for the real one?

Engineering internships and entry-level jobs in India, newest first.