Data Structures & AlgorithmsModerateCAT · TCS NQT

Problem: How many integers n with 1 ≤ n ≤ 1000 have decimal digits summing to exactly 10?

  1. A. 66
  2. B. 63
  3. C. 9
  4. D. 54

Correct answer: B. 63

Writing n as three digits a + b + c = 10 (1000 has digit sum 1) gives C(12, 2) = 66 solutions, minus the 3 that use a digit 10, so 63. Forgetting the digit ≤ 9 cap gives 66, counting only two-digit numbers gives 9, and counting only three-digit numbers gives 54.

More Coding Interview Problems questions

Exams that ask this topic