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 hereans=[]fordinqueries:iflen(arr)<=d:ans.append(max(arr))continueh=[a*-1forainarr[:d]]heapq.heapify(h)minVal=h[0]*-1deleted=[]foriinrange(1,len(arr)-d+1):heapq.heappush(deleted,arr[i-1]*-1)heapq.heappush(h,arr[i+d-1]*-1)whilehanddeletedandh[0]==deleted[0]:heapq.heappop(h)heapq.heappop(deleted)minVal=min(minVal,h[0]*-1)ans.append(minVal)returnans
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 →
Use heap