FreeCareerPath
Build the PrimitiveEasy

Single Number

Write `single_number(nums)` where every value appears twice except one. Return the one. Use O(1) extra space. single_number([4,1,2,1,2]) -> 4 A hash map solves it in O(n) space, which the constraint rules out. XOR is self-inverse and commutative, so every pair cancels regardless of order and the loner survives.

What to expect: A timer starts when you begin. Edit the starter code, run it against the test suite as many times as you like, then finish when you're done. The reference solution and interviewer follow-up questions unlock only after you finish.

Log in to start this session

Timed sessions and your results for "Single Number" are saved to your account — logging in takes a few seconds.

Single Number — FreeCareerPath