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.
Can't seem to figure out the problem. It gives correct output on running in my IDE.
#!/bin/python3importmathimportosimportrandomimportreimportsys# Complete the getWays function below.memoizing_dict={}# Complete the getWays function below.defgetWays(n,c):globalmemoizing_dictifn<0:return0elifn==0:return1elif(n,len(c))inmemoizing_dict.keys():returnmemoizing_dict[(n,len(c))]else:cum_sum=0forc_indexinrange(len(c)):c_item=c[c_index]ifc_item>n:continueelse:result=getWays(n-c_item,c[c_index:])ifresult>0:cum_sum+=resultmemoizing_dict[(n,len(c))]=cum_sumreturncum_sumif__name__=='__main__':fptr=open(os.environ['OUTPUT_PATH'],'w')nm=input().split()n=int(nm[0])m=int(nm[1])c=list(map(int,input().rstrip().split()))# Print the number of ways of making change for 'n' units using coins having the values given by 'c'ways=getWays(n,c)print(ways)fptr.close()
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 →
Can't seem to figure out the problem. It gives correct output on running in my IDE.