Data Structures & AlgorithmsModerateCAT · TCS NQT

Problem: How many non-negative integer solutions (x, y, z) satisfy x + y + z = 10?

  1. A. 66
  2. B. 55
  3. C. 220
  4. D. 36

Correct answer: A. 66

Stars and bars: 10 stars and 2 bars give C(12, 2) = 66. Using C(11, 2) = 55 is an off-by-one, C(12, 3) = 220 uses one bar too many, and 36 counts only positive solutions.

More Coding Interview Problems questions

Exams that ask this topic