Level 5 · Advanced Problem SolvingBUILD YOUR INTUITION
Bit Manipulation
Use bitwise identities to combine integer state. XOR has identity zero and cancels equal pairs.
THE MENTAL MODELWhen should this come to mind?
Use bitwise identities to combine integer state. XOR has identity zero and cancels equal pairs.
Paired values with one exceptionBinary flagsCompact masks What makes it work
JavaScript bitwise operators coerce to signed 32-bit integers. Inputs in this lesson fit that range; negative values use two's complement.
When to choose something else
XOR cancellation only solves Single Number under its exact frequency contract; arbitrary duplicates need counting.
See the pattern in action
Change the input. Follow the state. Make it yours.