Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

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

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

Correct answer: D. 3

A value is a power of two exactly when x AND (x - 1) is zero and x is nonzero. Checking pairs with a zero AND (the last option) answers a different question.

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

Exams that ask this topic