14. Sliding Window Maximum
HardDequeSliding Window
Print the maximum of every contiguous window of size k.
Input format
Line 1: n k Line 2: n integers
Output format
n − k + 1 space-separated maxima.
Example 1
Input
8 3 1 3 -1 -3 5 3 6 7
Output
3 3 5 5 6 7
Example 2
Input
1 1 1
Output
1
Constraints
1 ≤ k ≤ n ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.
Loading the MyLoginn IDE…