Data Structures & AlgorithmsModerateTCS NQT · CAT

Problem: How many integers n with 0 ≤ n ≤ 255 have exactly four 1-bits in their binary representation?

  1. A. 56
  2. B. 256
  3. C. 16
  4. D. 70

Correct answer: D. 70

Choose which 4 of the 8 bit positions are 1: C(8,4) = 70. C(8,3) = 56 picks three bits, 256 counts every byte, and 2⁴ = 16 confuses the count with a value.

More Coding Interview Problems questions

Exams that ask this topic