-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10.4_Peaks.cpp
More file actions
36 lines (29 loc) · 836 Bytes
/
10.4_Peaks.cpp
File metadata and controls
36 lines (29 loc) · 836 Bytes
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
33
34
35
36
#include <math.h>
int solution(vector<int> &A) {
if (A.size() < 3) {
return 0;
}
// STEP 1: Find the numbers that N is divisible by
int N = A.size();
vector<int> divisors, peaks;
for (int i = 2 ; i <= N/2; i++) {
if (N%i == 0) {
divisors.push_back(i);
}
}
for (unsigned int i = 0 ; i < divisors.size(); i++) {
cout << divisors[i] << " ";
}
cout << endl;
// STEP 2: Find locations of all peaks
for (int i = 1 ; i < N-1 ; i++) {
if (A[i] > A[i-1] && A[i] > A[i+1]) {
peaks.push_back(i);
}
}
for (unsigned int i = 0 ; i < peaks.size(); i++) {
cout << peaks[i] << " ";
}
// STEP 3: For each divisible number, check if the locations of the peaks work
return 0;
}