← Bit Manipulation Quiz: all 8 questions
Bit Manipulation Quiz · Question 4 of 8
Every number appears twice except one. Which operation finds the single number in O(1) space?
Every number appears twice except one. Which operation finds the single number in O(1) space?
- A.AND all numbers
- B.OR all numbers
- C.XOR all numbers
- D.Add all numbers
Answer & explanation
Correct answer: XOR all numbers
a ^ a = 0 and a ^ 0 = a, so all pairs cancel and the single number remains.
Can you get the rest right without peeking?
Take the timed Bit Manipulation Quiz quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →