Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

How many entries of [1, 6, 8, 12, 16, 33, 64, 0] are powers of two (with 1 counted)?

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

Correct answer: D. 4

A positive number is a power of two exactly when x AND (x - 1) is zero. Zero must be excluded explicitly, since 0 AND -1 is also zero in the naive test.

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

Exams that ask this topic