#C10745. Sliding Window Maximum
Sliding Window Maximum
Sliding Window Maximum
You are given an integer array nums
and a sliding window of size k. Your task is to find the maximum value in each sliding window as it moves from left to right over the array. Formally, for an array of length n, for every index i such that i ≥ k - 1, compute
\( M_i = \max(\{nums[i-k+1], nums[i-k+2], \dots, nums[i]\}) \)
The answer is a list of these maximum values for each valid window.
inputFormat
The first line contains two space-separated integers: n (the number of elements in the array) and k (the size of the sliding window). The second line contains n space-separated integers representing the array elements.
outputFormat
Output a single line containing the maximum value from each sliding window, separated by a single space.## sample
8 3
1 3 -1 -3 5 3 6 7
3 3 5 5 6 7