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.
[12, 60, 120, 240, 420, 720, 840, 1680, 2520, 4620]
this is the array i got. I am getting WA error for test case 4 and above. Can u tell me where is the problem?
below is my python3 solution for reference
importosimportsysfrommathimportsqrtfrombisectimportbisect_leftfromcollectionsimportdefaultdictdefbinary_search(a,x,lo=0,hi=None):# can't use a to specify default for hihi=hiifhiisnotNoneelselen(a)# hi defaults to len(a) pos=bisect_left(a,x,lo,hi)# find insertion positionreturn(posifpos!=hianda[pos]==xelse-1)# don't walk off the enddefbinarySearch(data,val):highIndex=len(data)-1lowIndex=0whilehighIndex>lowIndex:index=int((highIndex+lowIndex)/2)sub=data[index]ifdata[lowIndex]==val:return[lowIndex,lowIndex]elifsub==val:return[index,index]elifdata[highIndex]==val:return[highIndex,highIndex]elifsub>val:ifhighIndex==index:returnsorted([highIndex,lowIndex])highIndex=indexelse:iflowIndex==index:returnsorted([highIndex,lowIndex])lowIndex=indexreturnsorted([highIndex,lowIndex])s=[(i+1)*(i+1)foriinrange(2300)]d=defaultdict(lambda:0)foriinrange(len(s)):forjinrange(i+1,len(s)):k=binary_search(s,s[i]+s[j])+1ifk!=0:d[(i+1+j+1+k)]+=1temp=list(sorted(list(d.keys())))ans=list()maxValue=0foriintemp:ifd[i]>maxValue:ans+=[i]#print(d[i],i)maxValue=d[i]#print(ans)ans+=[5000001]foriinrange(int(input())):temp=int(input())l,h=binarySearch(ans,temp)print(ans[l])
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #39: Integer right triangles
You are viewing a single comment's thread. Return to all comments →
[12, 60, 120, 240, 420, 720, 840, 1680, 2520, 4620] this is the array i got. I am getting WA error for test case 4 and above. Can u tell me where is the problem?
below is my python3 solution for reference