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.
defsolve(arr,queries):# Write your code hereifnotarr:return[]n=len(arr)all_mins=[]fordinqueries:currMin=sys.maxsizeprevMax=-sys.maxsizeforiinrange(n-d+1):newMax=prevMax#mostlikelythenewinterval,withonly1moreelement,willhavethesamemaxdidthepreviousintervalifi==0:#firsttime,needtoactuallycalculatemaxnewMax=max(arr[i:i+d])else:ifarr[i-1]==prevMax:#ifthepreviousmaxindeedcamefromanelementinthepreviousintervalthatwearemissinginthisnewintervalnewMax=max(arr[i:i+d])ifnewMax<currMin:currMin=newMaxprevMax=newMaxall_mins.append(currMin)#print("all mins is: ", all_mins)returnall_mins
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Queries with Fixed Length
You are viewing a single comment's thread. Return to all comments →