Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE

Problem: The XOR of the values 1 through 10 is XOR-ed with the XOR of the values 1 through 9. What is the resulting value?

  1. A. 11
  2. B. 1
  3. C. 0
  4. D. 10

Correct answer: D. 10

XOR is its own inverse, so (1 ^ … ^ 10) ^ (1 ^ … ^ 9) cancels 1..9 and leaves 10. XOR(1..10) alone is 11, XOR(1..9) alone is 1, and 0 wrongly assumes every term cancels.

More Coding Interview Problems questions

Exams that ask this topic