Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

How many index pairs i < j in [1, 3, 5, 7, 9, 15] have a sum that is a power of two?

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

Correct answer: D. 5

A positive integer is a power of two when x AND (x - 1) is zero. Checking pair sums directly with that test avoids logarithms and floating point errors.

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

Exams that ask this topic