Data Structures & AlgorithmsVery hardProduct Company SDE · CP practice
Problem: How many integers in [1, 999] have digits that are strictly increasing (each digit larger than the previous)? Run the code.
Problem: How many integers in [1, 999] have digits that are strictly increasing (each digit larger than the previous)? Run the code.
print(sum(1 for x in range(1, 1000) if all(int(str(x)[i]) < int(str(x)[i + 1]) for i in range(len(str(x)) - 1))))What is printed?
- A. 129
- B. 219
- C. 165
- D. 120
Correct answer: A. 129
Strictly increasing digits from 1..9: C(9,1) + C(9,2) + C(9,3) = 9 + 36 + 84 = 129 (0 cannot lead). Non-decreasing gives 219, allowing a leading 0 gives 165, and C(10,3) = 120 counts only 3-digit picks including 0.
More Coding Interview Problems questions
- Problem: What is the sum of the first 50 terms of the sequence 1, 1, 2, 3, 5, ... (Fibonacci numbers F(1) to F(50), with F(1)=F(2)=1)? Run…
- Problem: How many pairs (i < j) of [2, 4, 6, 9, 12, 15] have gcd(ai, aj) = 3? Run the code. python from math import gcd a = [2, 4, 6, 9…
- Problem: How many integers in [1, 300] are divisible by exactly two of the numbers 2, 3 and 5? Run the code. python print(sum(1 for x in…
- Problem: What is the minimum number of perfect cubes (1, 8, 27, ...) that sum to 100? Run the DP. python INF = 10 9 dp = [0] + [INF] 100…
- Problem: How many integers in [1, 200] have an even number of 1-bits in their binary form? Run the code. python print(sum(1 for x in…
- Problem: What is the length of the longest subarray of [1, 1, 0, 1, 1, 1, 0, 1] containing at most one zero? Run the sliding-window code…