Maximum Element in Every Window
Mediumjavapythonccppjavascript
Given an integer array and a window size K, find the maximum element in every contiguous window of size K.
Input Format
The first line contains two integers N and K. The second line contains N space-separated integers.
Output Format
Print the maximum of each window (left to right), separated by single spaces.
Example 1
Input
8 3 1 3 -1 -3 5 3 6 7
Output
3 3 5 5 6 7
Explanation: Each output value is the largest among the corresponding three consecutive elements.
- 1 <= K <= N <= 100000
- -1000000000 <= A[i] <= 1000000000