#K85772. Sliding Window Maximum
Sliding Window Maximum
Sliding Window Maximum
Given an array of integers and a window size (k), compute the maximum value in each contiguous subarray (i.e., sliding window) of length (k). In other words, for each window, find the maximum element among the (k) elements. For example, if the array is [1, 3, -1, -3, 5, 3, 6, 7] with (k = 3), the output should be [3, 3, 5, 5, 6, 7].
inputFormat
The input is given via standard input. 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.
outputFormat
Output the maximum value in each sliding window in one line, with each number separated by a single space.## sample
8 3
1 3 -1 -3 5 3 6 7
3 3 5 5 6 7