For this Question: You are given an array A of size N. You have to print the maximum in every <b>K-sized subarray</b> from the left to the right in the array A.
More formally, you have to print N - K + 1 integers X<sub>1</sub>, X<sub>2</sub>, ..., X<sub>N-K+1</sub> such that X<sub>i</sub> (1 <= i <= N - K + 1) is the maximum element in the subarray A<sub>i</sub>, A<sub>i+1</sub>, ..., A<sub>i+K-1</sub>.1. The first line contains an integer N, denoting the size of the array.
2. The second line has N space-separated integers of the array A.
3. The third line contains integer K, denoting the size of the sliding window

<b>Constraints :</b>
1 &le; N &le; 10<sup>5</sup>
-10<sup>4</sup> &le; A[i] &le; 10<sup>4</sup>
1 &le; K &le; NPrint the max of K numbers for each position of sliding windowSample Input:-
8
1 3 -1 -3 5 3 6 7
3

Sample Output:-
3 3 5 5 6 7

Explanation:-
Window position       Max
- - - -
[1 3 -1] -3 5 3 6 7         3
1 [3 -1 -3] 5 3 6 7         3
1 3 [-1 -3 5] 3 6 7         5
1 3 -1 [-3 5 3] 6 7         5
1 3 -1 -3 [5 3 6] 7         6
1 3 -1 -3 5 [3 6 7]         7

Sample Input:-
1
1
1

Sample Output:-
1 , I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
vector<int> maxSwindow(vector<int>& arr, int k) {
vector<int> result;
deque<int> Q(k); // store the indices
// process the first window
for(int i = 0; i < k; i++) {
while(!Q.empty() and arr[i] >= arr[Q.back()])
Q.pop_back();
Q.push_back(i);
}
// process the remaining elements
for(int i = k; i < arr.size(); i++) {
// add the max of the current window
result.push_back(arr[Q.front()]);
// remove the elements going out of the window
while(!Q.empty() and Q.front() <= i - k)
Q.pop_front();
// remove the useless elements
while(!Q.empty() and arr[i] >= arr[Q.back()])
Q.pop_back();
// add the current element in the deque
Q.push_back(i);
}
result.push_back(arr[Q.front()]);
return result;
}
int main()
{
int k, n, m;
cin >> n;
vector<int> nums, res;
for(int i =0; i < n; i++){
cin >> m;
nums.push_back(m);
}
cin >> k;
res = maxSwindow(nums,k);
for(auto i = res.begin(); i!=res.end(); i++)
cout << *i << " ";
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not?