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.
Hello, the below is my solution :
I get error on this line :
temp_li.append(list(itertools.combinations(varying_range, r=i)))
Memory Error.
Please help me in resolving the same.
importitertoolsfromfunctoolsimportreducen,m=list(map(int,input().split()))heights=list(map(int,input().split()))heights=sorted(heights)deflist_of_l_r(l,r):temp_li=[]temp_li.clear()varying_range=list(range(l,r+1))len_=len(varying_range)foriinrange(1,len_+1):temp_li.append(list(itertools.combinations(varying_range,r=i)))print(len(temp_li))# yield list(itertools.combinations(varying_range, r=i))# li1 = list(itertools.combinations(varying_range, r=i))print(temp_li)returntemp_lideff(i,j):returni+jdefcalculate_power(collection):# retrieve the heights from the index# index comes from collectionsselected_height=[]foriincollection:selected_height.append(heights[i-1])# calculate power for themcombinations=list(itertools.product(selected_height,repeat=2))# print(combinations)power=0foritemsincombinations:power+=sum(items)# print(power)returnpowerdefreturnMin(matrix_of_indexes,x):height_max=[]formatrix_itemsinmatrix_of_indexes:forlist_itemsinmatrix_items:# print(list_items)power=calculate_power(list_items)ifpower>=x:# check for max value of heightforiinlist_items:height_max.append(heights[i-1])# print("final_heights", height_max)# print("minimum is :")# print(height_max)# print("before returning height_max:", list_items)returnmax(height_max);ifheight_max==[]:return-1foriinrange(m):l,r,x=list(map(int,input().split()))# print(l, r, x)# reproduce the sequencesmatrix_of_indexes=list_of_l_r(l,r)print(returnMin(matrix_of_indexes,x))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Basketball tournament
You are viewing a single comment's thread. Return to all comments →
Hello, the below is my solution : I get error on this line : temp_li.append(list(itertools.combinations(varying_range, r=i))) Memory Error. Please help me in resolving the same.
''' https://www.hackerrank.com/contests/hourrank-31/challenges/basketball-tournament-1/problem '''