Search⌘ K
AI Features

Solved Problem - Sliding Window Maximum

Explore how to solve the Sliding Window Maximum problem by efficiently maintaining a balanced data structure to track maximum values in subarrays of fixed size. Understand the process of replacing brute force with a multiset approach to achieve optimal time complexity suitable for large inputs.

Problem Statement

Given an array AA, of NN integers. Print the maximum integer in that subarray for all subarrays of length KK.

Input format

The first line contains two space-separated integers NN and KK (1KN105)(1 \leq K \leq N \leq 10^5). The second line contains NN space separated integers representing the array A[]A[] ...