classSolution { public: deque<pair<int,int> > mono_q; voidadd(int x, int ind){ while(mono_q.size()&&x>mono_q.back().first){ mono_q.pop_back(); } mono_q.push_back(pair(x,ind)); } voidpop(int lhs){ while(mono_q.size()&&mono_q.front().second<lhs)mono_q.pop_front(); } vector<int> maxInWindows(vector<int>& nums, int k){ vector<int> ans; // init the queue for(int i=0;i<k-1;i++){ add(nums[i],i); } // traverse all intervals for(int lhs = 0;lhs+k-1<nums.size();lhs++){ pop(lhs);// pop all the elements which are out of window add(nums[lhs+k-1], lhs+k-1); ans.push_back(mono_q.front().first); } return ans; } };