ProgrammingVery hardGATE CS & IT · Infosys

What is printed?

What is printed?
def ways(coins, amt):
    dp = [0] * (amt + 1)
    dp[0] = 1
    for c in coins:
        for v in range(c, amt + 1):
            dp[v] += dp[v - c]
    return dp[amt]
print(ways([1, 2, 5], 5), ways([2, 5], 3))
  1. A. 5 0
  2. B. 4 0
  3. C. 4 1
  4. D. 3 0

Correct answer: B. 4 0

This is unordered coin-change counting. 5 can be made as {5}, {2,2,1}, {2,1,1,1} and {1,1,1,1,1}, and 3 cannot be made from coins 2 and 5.

More Python Programming questions

Exams that ask this topic