You are viewing a single comment's thread. Return to all comments →
void printKMax(int arr[], int n, int k){ deque<int> q(arr,arr+k) ; int max = *std::max_element(q.begin(),q.begin()+k); cout<<max<<' '; for (int i=k;i<n;i++){ int front =q[0]; q.push_back(arr[i]); q.pop_front(); if (arr[i]>max){ max=arr[i]; } else if (max==front){ max = *std::max_element(q.begin(),q.begin()+k); } cout<<max<<" "; } cout<<endl; }
Seems like cookies are disabled on this browser, please enable them to open this website
Deque-STL
You are viewing a single comment's thread. Return to all comments →