Data Structures & AlgorithmsVery hardProduct Company SDE · CP practice

Problem: What is the count of 3-digit numbers whose digits are all distinct and in strictly increasing order? Run the code.

Problem: What is the count of 3-digit numbers whose digits are all distinct and in strictly increasing order? Run the code.
print(sum(1 for x in range(100, 1000) if all(int(str(x)[i]) < int(str(x)[i + 1]) for i in range(2))))
What is printed?
  1. A. 120
  2. B. 165
  3. C. 84
  4. D. 720

Correct answer: C. 84

Three distinct non-zero digits in increasing order: C(9,3) = 84 (a 0 can never be first or later). C(10,3) = 120 wrongly allows 0, non-decreasing gives 165, and 10 · 9 · 8 = 720 counts ordered choices.

More Coding Interview Problems questions

Exams that ask this topic