Missing Number
Find the one missing value from the range 0..n.
Why does this pattern fit?
Restate the exact job
Find the one missing value from the range 0..n.
Equal values cancel under XOR, leaving only the missing value.
O(n) time · O(1) space
Summation can overflow in fixed-width languages.
How to solve Missing Number
The goal is to solve this problem from the pattern, not to memorize a finished answer. Use this as a check after your own attempt.
What the question asks
Find the one missing value from the range 0..n.
Why Bit manipulation fits
Equal values cancel under XOR, leaving only the missing value.
State to maintain
An accumulator initialized to n.
Transition
XOR every index and value into the accumulator.
Time and space
O(n) time · O(1) space
Counterexample to the tempting mistake
Summation can overflow in fixed-width languages.
Prove it again tomorrow
Close this page. Rebuild the state and transition from memory, write a test that exposes the mistake above, then solve a fresh input without looking back. A same-day reread is practice, not proof of retention.