Skip to content
BytePatterns

Two Lone Values

MediumBit Manipulation#xor-cancel#bit-partition~30m

Problem

In a list of integers, every value appears exactly twice except two different values that appear once each. Return those two, smaller first. Use linear time and constant extra space, so a tally of every value is not allowed.

Examples

Input:  nums = [1, 2, 1, 3, 2, 5]
Output: [3, 5]
Input:  nums = [2, 0, 2, 6]
Output: [0, 6]
Why:    zero can be one of the lone values
Input:  nums = [4, 9]
Output: [4, 9]
Why:    edge case, no pairs at all, only the two lone values

Hints

0 / 3

Stuck on the idea rather than the code? XOR Tricks covers it.