```
vector<int> maxSlidingWindow(vector<int>& nums, int k) {
if(nums.empty()) return {};
vector<int> res;
int n=nums.size()-k+1;
if(n>0){
for(int i=0;i<n;i++) res.push_back(*max_element(nums.begin()+i,nums.begin()+i+k));
}
return res;
}
```

- step1: calculate the size of the result-> nums.size()-k+1;
- step2: select the max value in each k subarray of nums;