Data Structures & AlgorithmsModerateProduct Company SDE · CP practice

Problem: What is the number of integers in [1, 999] whose digit product is 0? Run the code.

Problem: What is the number of integers in [1, 999] whose digit product is 0? Run the code.
print(sum(1 for x in range(1, 1000) if '0' in str(x)))
What is printed?
  1. A. 180
  2. B. 171
  3. C. 189
  4. D. 99

Correct answer: A. 180

Two-digit numbers with a zero: 9; three-digit: 900 − 729 = 171; total 180. Counting only three-digit numbers gives 171, counting zero digits instead of numbers gives 189, and checking only the last digit gives 99.

More Coding Interview Problems questions

Exams that ask this topic