Data Structures & AlgorithmsHardProduct Company SDE · CP practice

Problem: How many ways are there to make 15 from unlimited coins of value 1, 5 and 10 (order does not matter)? Run the DP.

Problem: How many ways are there to make 15 from unlimited coins of value 1, 5 and 10 (order does not matter)? Run the DP.
ways = [1] + [0] * 15
for c in (1, 5, 10):
    for v in range(c, 16):
        ways[v] += ways[v - c]
print(ways[15])
What is printed?
  1. A. 6
  2. B. 42
  3. C. 2
  4. D. 4

Correct answer: A. 6

Processing one coin type at a time counts multisets: 15 = 10+5, 10+1×5, 5×3, 5×2+1×5, 5+1×10, 1×15, so 6. Looping amounts outside coins counts ordered sequences (42), dropping the 1-coin gives 2, and 4 is the count for 10.

More Coding Interview Problems questions

Exams that ask this topic