Data Structures & AlgorithmsHardTCS NQT Digital · counting

Problem: How many integers in [1, 1000] contain the digit 0? Run the code.

Problem: How many integers in [1, 1000] contain the digit 0? Run the code.
print(sum(1 for x in range(1, 1001) if '0' in str(x)))
What is printed?
  1. A. 181
  2. B. 189
  3. C. 171
  4. D. 190

Correct answer: A. 181

Nine two-digit numbers (10 to 90) and 171 three-digit numbers contain a 0, and 1000 adds one more, for 181.

More Coding Interview Problems questions

Exams that ask this topic