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+n); auto max = *std::max_element(d.begin(), d.begin()+k); cout << max; while (d.size() > k) { auto front = d.front(); d.pop_front(); if (d[k-1] >= max) { max = d[k-1]; } else if (front == max) { max = *std::max_element(d.begin(), d.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 →