Why does my code time out even with stress testing set to False?
memo={}
memo[0]=1
def ways(bills,amount):
if (bills==[]):
if amount ==0: memo[(tuple(bills),amount)]=1 return 1 else: memo[(tuple(bills),amount)]=0 return 0
bills.sort()
if amount==0:
memo[(tuple(bills),amount)]=1 return 1
elif amount < min(bills):
memo[(tuple(bills),amount)]=0 return 0
if (tuple(bills),amount) in memo:
return memo[(tuple(bills), amount)]
else:
l= amount // bills[0] s=0 for i in range(l): s=s+ways(bills[1:],amount -(i+1)*bills[0] ) memo[(tuple(bills), amount -(i+1)*bills[0])]=s return s
def countways(bills, amount):
write your code here
return ways(bills,amount)
stressTesting = False
I’m using memoization so whats the problem?