Data Structures & AlgorithmsModerateICPC regional · Amazon SDE OA

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

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

Correct answer: C. 3 5

XOR of all elements equals a ^ b where a and b are the two singletons. Split the set by a set bit of that XOR to separate them; a single-value XOR is not enough to identify both.

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

Exams that ask this topic