Data Structures & AlgorithmsModerateCAT · TCS NQT
Problem: How many non-negative integer solutions (x, y, z) satisfy x + y + z = 10?
- A. 66
- B. 55
- C. 220
- 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
- Problem: How many integer solutions (x, y, z) with x, y, z ≥ 1 satisfy x + y + z = 10?
- 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…