rishu110067

Untitled

Feb 2nd, 2022 (edited)
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. def number_of_ways(coins,amount):
  2.     final_sol = []
  3.     def helper(idx,amount_sofar,ps):
  4.         if amount_sofar == 0 :
  5.             # print("recusrion done final ps",ps)
  6.             final_sol.append(ps[:])
  7.             return 1
  8.         total = 0
  9.         for i in range(idx,len(coins)):
  10.             # print("coin is ", coins[i], "ps is ", ps, "amount_sofar-coins[i]", amount_sofar - coins[i])
  11.             if amount_sofar >= coins[i]:
  12.                ps.append(coins[i])
  13.                total = total + helper(i, amount_sofar-coins[i],ps)
  14.                ps.pop()
  15.         return total
  16.     return helper(0,amount,[])
  17.    
Add Comment
Please, Sign In to add comment