We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
defgetWays(n,c):dp=[[0forcolinrange(len(c)+1)]forrowinrange(n+1)]# All empty coins can solve no amount except amount 0.foriinrange(len(c)+1):dp[0][i]=1foramountinrange(1,n+1):forendinrange(len(c)):ifamount-c[end]>=0:dp[amount][end+1]=dp[amount-c[end]][end+1]+dp[amount][end]else:dp[amount][end+1]=dp[amount][end]returndp[n][len(c)]
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
The Coin Change Problem
You are viewing a single comment's thread. Return to all comments →
Python DP based on the recursion: