You are viewing a single comment's thread. Return to all comments →
void printKMax(int arr[], int n, int k){ deque<int> q; for (int i = 0; i < n; ++i){ while (!q.empty() && arr[q.front()] < arr[i]) q.pop_front(); q.push_front(i); if (i + 1 >= k){ cout << arr[q.back()]; if (i + 1 == n) cout << "\n"; else cout << " "; if (q.back() == i+1-k) q.pop_back(); } } }
Deque-STL
You are viewing a single comment's thread. Return to all comments →