Data Structures & AlgorithmsModerateCAT · TCS NQT
Problem: How many integer solutions (x, y, z) with x, y, z ≥ 1 satisfy x + y + z = 10?
- A. 66
- B. 36
- C. 45
- 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
- Problem: A derangement is a permutation with no fixed point. How many derangements of 5 objects exist?
- Problem: How many binary trees (distinct shapes, ignoring labels) can be formed with 6 nodes?
- Problem: Count the integers from 1 to 64 whose binary representation has an even number of 1-bits.
- Problem: For the string "aaabbbbcc" with at most one replacement of any character by any other letter, what is the length of the longest…
- Problem: The array [1, 4, 3, 2] (with even length) is split into two-element pairs in any way, and the minimum of each pair is added up…
- Problem: A matrix stores the number of paths in a 3×3 grid where each cell can be entered from the left or from above, and blocked cells…