Data Structures & AlgorithmsHardProduct Company SDE · CP practice

Problem: How many integers in [1, 10000] have decimal digits summing to 12? Run the code.

Problem: How many integers in [1, 10000] have decimal digits summing to 12? Run the code.
print(sum(1 for x in range(1, 10001) if sum(map(int, str(x))) == 12))
What is printed?
  1. A. 415
  2. B. 416
  3. C. 414
  4. D. 420

Correct answer: A. 415

A digit-by-digit count (each digit 0 to 9, length up to 4) gives 415 integers in [1, 10000] whose digit sum is 12.

More Coding Interview Problems questions

Exams that ask this topic