Bit tricks for coding interviews
Tap to start →
x ^ x = 0. XOR all numbers and the one without a pair is left.
n & 1 is 1 for odd numbers, 0 for even.
Shifting left by 1 doubles a number. Shifting right halves it.
It's 0 only when n is a power of two.
Forgetting brackets: n & 1 == 0 is read as n & (1 == 0). Write (n & 1) == 0.
Tap an answer. The full video explains why.
Free DSA in Java course. Subscribe to Compiled Canvas on YouTube.