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)?

  1. A. 14
  2. B. 30
  3. C. 20
  4. 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

Exams that ask this topic