Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA

How many integers x with 0 <= x <= 1000 have exactly four 1-bits in their binary representation?

  1. A. 210
  2. B. 211
  3. C. 120
  4. D. 212

Correct answer: A. 210

Count the numbers with four 1-bits directly, or with a digit DP over the binary digits of the bound. Extending the range to 1024 adds numbers above 1000 and changes the count.

More Coding Interview Problems questions

Exams that ask this topic