Missing or unique-number problems whose input guarantees exact pairing.
- every value appears twice except one
- numbers come from a known range
- constant extra space
All matched values cancel regardless of processing order, while the unmatched value remains.
O(n) time. Typical auxiliary space: O(1).
JAVA STARTING POINT
A template to adapt, not memorize.
int answer = 0;
for (int value : values) {
answer ^= value;
}Common mistakes
- Using XOR without the required pairing guarantee
- Forgetting expected range values
- Treating XOR as addition
PUBLISHED / 01
Learn in this order.
Available articles always appear before the publishing plan.
Find the Missing Number
Find the missing value from 1 through n using XOR without overflow.
Read article →PLANNED PRACTICE
What comes after the published lessons.
- Single numberPlanned, not yet published
- Find two unique numbersPlanned, not yet published
