Data Structures & AlgorithmsHardTCS NQT Digital · ICPC regional

Problem: Let f(n) = number of 1-bits in n. Compute Σ f(n) for n from 0 to 63 inclusive.

  1. A. 192
  2. B. 384
  3. C. 160
  4. D. 224

Correct answer: A. 192

Each of the 6 bit positions is set in exactly 32 of the 64 numbers 0..63, so the total is 6 × 32 = 192. Forgetting the 'half' gives 6 × 64 = 384, using 5 bits gives 160, and assuming 7 bits gives 224.

More Coding Interview Problems questions

Exams that ask this topic