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 heredefget_val(arr,d):max_record=deque()ans=float('inf')foriinrange(n):whilemax_recordandarr[max_record[-1]]<=arr[i]:max_record.pop()max_record.append(i)ifmax_record[0]<=i-d:max_record.popleft()ifi>=d-1:ans=min(ans,arr[max_record[0]])returnansreturn[get_val(arr,q)forqinqueries]
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 →
Monotonic two-sided queue in Python 3 (accepted):