Data Structures & AlgorithmsHardGATE CS
How many integers n with 1 ≤ n ≤ 999 have digit sum exactly 12 and contain no digit 0 (in their usual decimal form, without leading zeros)?
- A. 66
- B. 73
- C. 52
- D. 59
Correct answer: D. 59
Enumerate n and test both conditions: 59 numbers qualify, of which 52 have three digits. Dropping the no-zero condition gives 73.
More Coding Interview Problems questions
- Find the length of the longest common subsequence of X = "AGGTABQXZRYWM" and Y = "GXTXAYBZQMWRY".
- What is the minimum number of characters that must be inserted anywhere in "CBAABDCABBDAC" to make it a palindrome?
- Matrices A1…A7 have dimensions 5×10, 10×3, 3×12, 12×5, 5×50, 50×6, 6×8. What is the minimum number of scalar multiplications needed to…
- A 2 × 11 board is tiled completely using 1 × 2 dominoes (placed either way) and 2 × 2 squares. How many different tilings are there?
- The 3 × 3 grid graph (9 vertices, 12 edges) has a diagonal edge added between its top-left corner and its centre vertex, giving a 13-edge…
- 50 people stand in a circle numbered 1 to 50. Starting the count at person 1, every 7th person (counting the first as 1) is removed, and…