Data Structures & AlgorithmsModerateTCS NQT · CAT

Problem: Count the integers from 1 to 64 whose binary representation has an even number of 1-bits.

  1. A. 31
  2. B. 32
  3. C. 33
  4. D. 15

Correct answer: A. 31

Among 0..63 exactly half (32) have an even popcount, including 0; removing 0 and noting 64 = 1000000 has one bit leaves 31. Including 0 gives 32, counting odd popcounts gives 33, and counting only numbers with exactly two 1-bits gives C(6, 2) = 15.

More Coding Interview Problems questions

Exams that ask this topic