Data Structures & AlgorithmsModerateTCS NQT · counting

Problem: How many integers in [100, 999] have all three digits distinct? Run the code.

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

Correct answer: B. 648

The first digit has 9 options (not 0), the second has 9 (not the first), and the third has 8, giving 9 * 9 * 8 = 648.

More Coding Interview Problems questions

Exams that ask this topic