The Peak Detector
Fenwick Mill logs a vibration reading from the main press once a minute. A reading that sits strictly above both of its neighbours is a knock — the press catching on something — and maintenance counts knocks per shift. A reading merely level with a neighbour is not a knock; that is the press running rough, which is a different report altogether.
Task: Print how many knocks the log contains.
Input
The first line holds an integer n, always at least 3. Each of the next n lines holds one reading.
Output
One line: a whole number. The first and last readings can never be knocks, since each has only one neighbour to be compared against. Print 0 when the log holds none.
Example:
Input:
5
1
3
2
4
1
Output:
2
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in