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.
I used generating functions to solve. The maths works out (I checked the functions and the method on my computer) but I got a runtime error when I submitted to Hackerrank. I'm not sure what I'm doing wrong because I didn't get any other error code
#!/bin/python3importmathimportosimportrandomimportreimportsysimportnumpy## Complete the 'getWays' function below.## The function is expected to return a LONG_INTEGER.# The function accepts following parameters:# 1. INTEGER n# 2. LONG_INTEGER_ARRAY c#deff(l):t=[1]forpolyinl:t=numpy.polynomial.polynomial.polymul(t,poly)returntdefmakePoly(degree,n):i=[]index=0whileindex<=n:ifindex%degree==0:i.append(1)else:i.append(0)index+=1returnidefgetWays(n,c):# Write your code herel=[]fordeginc:l.append(makePoly(deg,n))result=f(l)print(int(result[n]))if__name__=='__main__':fptr=open(os.environ['OUTPUT_PATH'],'w')first_multiple_input=input().rstrip().split()n=int(first_multiple_input[0])m=int(first_multiple_input[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)fptr.write(str(ways)+'\n')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 →
I used generating functions to solve. The maths works out (I checked the functions and the method on my computer) but I got a runtime error when I submitted to Hackerrank. I'm not sure what I'm doing wrong because I didn't get any other error code