🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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])
  1. A.7
  2. B.4
  3. C.3
  4. 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 →