Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div2 B

How many index pairs i < j in [1, 2, 3, 4, 5] have a[i] XOR a[j] equal to a power of two?

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

Correct answer: B. 4

A value is a power of two exactly when it is non-zero and x & (x - 1) = 0. Checking all ten pairs by hand is quick, and hashing scales it up.

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

Exams that ask this topic