Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 B

How many index pairs i < j satisfy a[i] XOR a[j] = 6 for the array [1, 4, 7, 2, 5, 3, 6]?

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

Correct answer: A. 3

Use a hash count of values seen so far: for each new x, look up x XOR 6. The pairs must be unordered, so each one counts once.

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

Exams that ask this topic