-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdequeSTL.cpp
32 lines (25 loc) · 819 Bytes
/
dequeSTL.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <algorithm>
// problem : https://www.hackerrank.com/challenges/deque-stl/problem
// soultion ========================================================
void printKMax(int arr[], int n, int k) {
int max = *std::max_element(arr, arr + k);
std::cout << max << " ";
for (int i = 1; i <= (n - k); i += 1) {
if (arr[k + i - 1] > max) {
max = arr[k + i - 1];
std::cout << max << " ";
continue;
}
if (arr[i - 1] != max) {
std::cout << max << " ";
}
else {
max = *std::max_element(&arr[i], &arr[i + k]);
std::cout << max << " ";
continue;
}
}
std::cout << std::endl;
}
//=======================================================================