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.
rows = len(c)
cols = n + 1
dp = [[0 for _ in range(cols)] for _ in range(rows)]
for row in range(rows):
for col in range(cols):
if col == 0:
dp[row][col] = 1
elif row == 0:
if col < c[row]:
dp[row][col] = 0
else:
dp[row][col] = dp[row][col-c[row]]
else:
if col < c[row]:
dp[row][col] = dp[row-1][col]
else:
dp[row][col] = dp[row-1][col] + dp[row][col-c[row]]
return dp[rows-1][cols-1]
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 →
My super non-slick code. Passed all tests though.
def getWays(n, c): # Write your code here