Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE
Problem: How many ways can the total 10 be formed as an unordered multiset of parts chosen from {1, 2, 3, 5} (repetition allowed)?
- A. 14
- B. 30
- C. 20
- D. 331
Correct answer: C. 20
A coin-change DP with the part loop outside the total loop counts each multiset once: 20. Forgetting part 5 gives 14, also allowing part 4 gives 30, and putting the total loop outside counts ordered sequences (331).
More Coding Interview Problems questions
- Problem: A 3×3 matrix is [[2,1,3],[6,5,4],[7,8,9]]. A falling path moves from a cell in row r to a cell in row r+1 in the same column or…
- Problem: Video clips of the form [start, end] cover the interval [0, 10]. The clips are [0,2], [4,6], [8,10], [1,9], [2,5], [5,7]. What is…
- Problem: The stock span of a day is the number of consecutive days (including today) up to and including today with a price at most…
- Problem: Five customers with service times 5, 3, 8, 2, 4 (in arrival order) are served by two tellers. Each customer goes to whichever…
- Problem: How many ordered pairs (a, b) of positive integers satisfy a × b = 36 with a ≤ 100 and b ≤ 100?
- Problem: How many non-negative integer solutions (x, y, z) satisfy x + y + z = 10?