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?
- A. 120
- B. 165
- C. 84
- 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
- Problem: What is the sum of the first 100 positive integers that are not divisible by 3? Run the code. python print(sum(x for x in…
- Problem: How many distinct values does x mod 12 take over the numbers x in [1, 1000] that are not divisible by 4? Run the code. python…
- Problem: What is the length of the longest palindromic substring of 'abacdcaba'? Run the code. python s = 'abacdcaba' best = 0 for c in…
- Problem: How many integers in [1, 10000] have a digit sum that is divisible by 7? Run the code. python print(sum(1 for x in range(1…
- Problem: How many integer solutions (a, b) with 1 <= a <= b <= 20 satisfy a b = 36? Run the code. python print(sum(1 for a in range(1, 21)…
- Problem: What is the length of the longest common subsequence of 'abcdef' and 'acebdf'? Run the DP. python a, b = 'abcdef', 'acebdf' dp =…