#K68407. Sliding Window Maximum
Sliding Window Maximum
Sliding Window Maximum
You are given an array of n integers and an integer k representing the size of a sliding window. Your task is to compute the maximum value in each window as it slides over the array from left to right.
The sliding window is defined as a contiguous segment of the array. For each position where the window fully fits inside the array, output the maximum element found in that window.
Note: If the array is empty or if k is 0, output an empty result.
Input/Output Format:
- The first line of input contains two integers, n and k, where n is the number of elements in the array.
- The second line contains n space-separated integers.
- The output should be a single line containing the maximum values for each sliding window, separated by a space.
The problem can be formulated using the following equation for each window starting at index i (0-indexed):
for all valid i such that 0 \leq i \leq n-k.
inputFormat
The first line contains two space-separated 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 a single line with the maximum of each sliding window, with each number separated by a space. If there are no windows (e.g., when n = 0 or k = 0), output an empty line.
## sample8 3
1 3 -1 -3 5 3 6 7
3 3 5 5 6 7