Queries with Fixed Length

  • + 0 comments
    def solve(arr, queries):   
        mins = []
    
        for k in queries:
            current_window = deque()
            maxs = []
            for i in range(len(arr)):
                if current_window and current_window[0] < i - k + 1:
                    current_window.popleft()
    
                while current_window and arr[current_window[-1]] < arr[i]:
                    current_window.pop()
    
    
                current_window.append(i)
    
                if i >= k -1:
                    maxs.append(arr[current_window[0]])
            mins.append(min(maxs))
    
        return mins