← Quiz: Bitwise Operators in C: all 15 questions
Quiz: Bitwise Operators in C · Question 8 of 15
Every number in an array appears twice except one. Which operation finds the single one in O(n) time and O(1) space?
Every number in an array appears twice except one. Which operation finds the single one in O(n) time and O(1) space?
- A.AND all the numbers
- B.OR all the numbers
- C.XOR all the numbers
- D.Add all the numbers and divide by 2
Answer & explanation
Correct answer: XOR all the numbers
x ^ x = 0, so pairs cancel and only the single number is left.
Can you get the rest right without peeking?
Take the timed Quiz: Bitwise Operators in C quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →