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.
fromcollectionsimportdequedefmin_of_max_in_subarrays_with_size(d,arr):# use sliding window to iterate through arraydq=deque()candidtaes=[]foriinrange(len(arr)):# remove out-of-window indexifdqanddq[0]<=i-d:dq.popleft()# before adding the current index, make sure to remove all indexes# indicating to value not larger than that of the current i# this way can make sure the maximum is in the front of queuewhiledqandarr[dq[-1]]<=arr[i]:dq.pop()dq.append(i)# add to max subarraysifi>=d-1:candidtaes.append(arr[dq[0]])returnmin(candidtaes)defsolve(arr,queries):result=[]#theminofmaxsubarrayswithsizedfordinqueries:result.append(min_of_max_in_subarrays_with_size(d,arr))returnresult
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 →