#K42562. Counting Peaks
Counting Peaks
Counting Peaks
You are given a list of integers representing altitudes. A peak is defined as an element which is strictly greater than its immediate neighbors. In other words, an index i (1 ≤ i ≤ n-2) is a peak if \(a_i > a_{i-1}\) and \(a_i > a_{i+1}\). Your task is to determine the number of peaks in the given array.
Constraints:
- 3 ≤ n ≤ 106
- Each altitude is an integer.
Example: For an input array [1, 3, 2, 4, 1], there are 2 peaks (at indices 1 and 3), so the output is 2.
inputFormat
The first line contains a single integer n, the number of elements in the array.
The second line contains n space-separated integers representing the altitudes.
Input is read from standard input (stdin).
outputFormat
Output a single integer representing the number of peaks in the array.
Output should be written to standard output (stdout).
## sample5
1 3 2 4 1
2