Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 B

What is the number of distinct values of a[i] XOR a[j] over all pairs i < j of the array [1, 2, 3, 4]?

  1. A. 6
  2. B. 7
  3. C. 1
  4. D. 12

Correct answer: A. 6

The six pair XORs are 3, 2, 5, 1, 6, 7, all different, so there are 6 distinct values. 7 is the largest XOR rather than a count, 1 is the smallest, and 12 counts ordered pairs.

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

Exams that ask this topic