FunctionRacerProblemsRace

Two Unpaired Numbers

MediumBitsPython, JavaScript, TypeScript, Java, C++

Every number in nums appears exactly twice, except for two different numbers that each appear exactly once. Return those two numbers as a list of two items in increasing order. There is a one pass solution with constant extra memory: the XOR of the whole list is the XOR of the two answers, and any 1 bit of that value tells the two apart.

Example 1

nums [1,2,1,3,2,5]
returns [3,5]

1 and 2 appear twice; 3 and 5 appear once.

Example 2

nums [4,9]
returns [4,9]

Both numbers appear once; 4 is the smaller one.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Bits problems