Data Structures & AlgorithmsModerateCAT · TCS NQT

Problem: How many integer solutions (x, y, z) with x, y, z ≥ 1 satisfy x + y + z = 10?

  1. A. 66
  2. B. 36
  3. C. 45
  4. D. 84

Correct answer: B. 36

Set x' = x − 1 etc., so x' + y' + z' = 7 with non-negative parts: C(9, 2) = 36 (or choose 2 of the 9 gaps between 10 stars). Allowing zeros gives 66, C(10, 2) = 45 is an off-by-one, and C(9, 3) = 84 picks three gaps instead of two.

More Coding Interview Problems questions

Exams that ask this topic