Data Structures & AlgorithmsHardCAT · TCS NQT
Problem: How many 5-digit numbers (10000–99999) have digits that sum to exactly 6 and begin with the digit 1?
- A. 126
- B. 56
- C. 84
- D. 35
Correct answer: B. 56
After the leading 1, four digits sum to 5: C(5 + 3, 3) = 56 (no digit can exceed 9 here). C(9,4) = 126 and C(9,3) = 84 use the wrong stars-and-bars parameters, and 35 forces every digit to be at least 1.
More Coding Interview Problems questions
- Problem: A string of 6 characters is formed from the letters {a, b} such that no two adjacent characters are equal. How many such strings…
- Problem: The Euclidean distance squared between (1,2) and (4,6) is what integer?
- Problem: In the sequence 2, 3, 5, 8, 12, 17, … each term increases by one more than the previous increase (differences 1, 2, 3, 4, …)…
- Problem: How many 4-element subsets of {1, 2, ..., 8} have a sum that is a multiple of 5?
- Problem: The array [4, 9, 16, 25] has its square roots summed. What is the sum of the square roots of these four numbers?
- Problem: A grid has 5 cells in a row, each painted red or blue. How many colourings have no two adjacent cells of the same colour?