Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def number_of_ways(coins,amount):
- final_sol = []
- def helper(idx,amount_sofar,ps):
- if amount_sofar == 0 :
- # print("recusrion done final ps",ps)
- final_sol.append(ps[:])
- return 1
- total = 0
- for i in range(idx,len(coins)):
- # print("coin is ", coins[i], "ps is ", ps, "amount_sofar-coins[i]", amount_sofar - coins[i])
- if amount_sofar >= coins[i]:
- ps.append(coins[i])
- total = total + helper(i, amount_sofar-coins[i],ps)
- ps.pop()
- return total
- return helper(0,amount,[])
Add Comment
Please, Sign In to add comment