← Quiz: 1D Dynamic Programming Patterns: all 10 questions
Quiz: 1D Dynamic Programming Patterns · Question 5 of 10
What does this print? (code)
What does this print?
coins, amount = [1, 2, 3], 4
ways = [1] + [0] * amount
for c in coins:
for x in range(c, amount + 1):
ways[x] += ways[x - c]
print(ways[amount])
- A.7
- B.4
- C.3
- D.5
Answer & explanation
Correct answer: 4
The combinations are 1+1+1+1, 1+1+2, 2+2 and 1+3.
Can you get the rest right without peeking?
Take the timed Quiz: 1D Dynamic Programming Patterns quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →