Data Structures & AlgorithmsVery hardProduct Company SDE · CP practice

Problem: How many integers in [1, 1000] have exactly three distinct decimal digits? Run the code.

Problem: How many integers in [1, 1000] have exactly three distinct decimal digits? Run the code.
print(sum(1 for x in range(1, 1001) if len(set(str(x))) == 3))
What is printed?
  1. A. 720
  2. B. 900
  3. C. 504
  4. D. 648

Correct answer: D. 648

Only 3-digit numbers qualify: 9 · 9 · 8 = 648 (first digit non-zero). 10 · 9 · 8 = 720 allows a leading zero, 900 counts all 3-digit numbers, and 9 · 8 · 7 = 504 wrongly bans 0 everywhere.

More Coding Interview Problems questions

Exams that ask this topic