Data Structures & AlgorithmsModerateCAT · TCS NQT
Problem: How many three-digit numbers (100 to 999) have strictly increasing digits from left to right (for example 147 qualifies, 151 does not)?
- A. 120
- B. 165
- C. 84
- D. 504
Correct answer: C. 84
Any 3 distinct digits from 1-9 can be arranged in exactly one increasing order (0 cannot lead), so C(9, 3) = 84. Allowing 0 gives C(10, 3) = 120, allowing equal digits (non-decreasing) gives C(11, 3) = 165, and counting all numbers with distinct digits 1-9 gives 9·8·7 = 504.
More Coding Interview Problems questions
- Array a = [1, 2, 3, 4, -1, 5, 0, 2]. How many contiguous subarrays have a sum of exactly 10?
- Array a = [2, -2, 3, -3, 4, -4, 1]. How many DISTINCT values appear among the prefix sums P[0], P[1], ..., P[7] (including P[0] = 0)?
- Sorted arrays A = [3, 8, 12, 17, 25] and B = [5, 9, 14, 20]. Choose one element from A and one from B so that the sum is as large as…
- Balloons span closed integer intervals [1,4], [2,3], [4,6], [5,8], [7,9]. One arrow shot at integer x bursts every balloon whose interval…
- How many binary strings of length 6 contain neither two consecutive 0s nor three consecutive 1s?
- How many subsets (including the empty subset) of [3, 5, 9, 11, 14, 2] have a sum divisible by 7?