Data Structures & AlgorithmsModerateTCS NQT · DP warm-up

Problem: How many ways can 10 be formed as an ordered-free sum of coins 1, 2 and 5 (each coin may be used any number of times, and order does not matter)?

Problem: How many ways can 10 be formed as an ordered-free sum of coins 1, 2 and 5 (each coin may be used any number of times, and order does not matter)?
ways = [1] + [0] * 10
for c in [1, 2, 5]:
    for v in range(c, 11):
        ways[v] += ways[v - c]
print(ways[10])
What is printed?
  1. A. 6
  2. B. 12
  3. C. 10
  4. D. 8

Correct answer: C. 10

Using 0, 1 or 2 fives gives 6 + 3 + 1 = 10 combinations of the 1s and 2s. Counting ordered sequences instead would give a much larger number.

More Coding Interview Problems questions

Exams that ask this topic