#K68807. Sliding Window Maximum
Sliding Window Maximum
Sliding Window Maximum
Given an integer array \(nums\) and an integer \(k\) representing the size of a sliding window, your task is to find the maximum value in each sliding window. In other words, for every contiguous subarray of length \(k\), output its maximum value.
More formally, for an array \(nums = [a_1, a_2, \dots, a_n]\) and a window size \(k\), for every valid index \(i\) (where \(1 \le i \le n-k+1\)), compute:
[ \max{a_i, a_{i+1}, \dots, a_{i+k-1}} ]
Please note that the input will be provided via standard input and your program should write the result to standard output.
inputFormat
The input is given from standard input (stdin) in the following format:
- The first line contains two integers \(n\) and \(k\), where \(n\) is the number of elements in the array and \(k\) is the size of the sliding window.
- The second line contains \(n\) space-separated integers representing the elements of the array \(nums\).
It is guaranteed that \(1 \le k \le n \le 10^5\) and the numbers fit in a 32-bit signed integer.
outputFormat
The output should be written to standard output (stdout) as a sequence of \(n-k+1\) space-separated integers. Each integer represents the maximum value in the corresponding sliding window of size \(k\).
## sample8 3
1 3 -1 -3 5 3 6 7
3 3 5 5 6 7
</p>