Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div 2

In [1, 2, 1, 3, 2, 5] exactly two values appear once and every other value appears twice. Which two values are they?

  1. A. 3 and 5
  2. B. 1 and 5
  3. C. 3 and 6
  4. D. 2 and 5

Correct answer: A. 3 and 5

The XOR of all values is 3 ⊕ 5 = 6, so the bit of value 2 differs between the two answers. Splitting by that bit and XORing each group gives 3 and 5.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic