You are viewing a single comment's thread. Return to all comments →
void printKMax(int arr[], int n, int k){
deque<int> d(arr, arr+k); //only initiate required window auto a = *std::max_element(d.begin(), d.begin()+k); for(int i = 0; i<n-k+1; i++){ cout << a << " "; d.push_back(arr[i+k]); d.pop_front(); if(d.back() > a){ //new element entering window a = *std::max_element(d.begin(), d.end()); } else if (arr[i] == a) { //max element exiting window a = *std::max_element(d.begin(), d.end()); } } 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 →
void printKMax(int arr[], int n, int k){
}