CT142

Count the Local High Points

EasyL2 · Byte BanditAcceptance: 0.0%XP: 10

A trail mapper marks a peak only when it is strictly taller than both neighboring points. Task: Count strict local maxima, excluding endpoints. Input format: Read n followed by n integers. Output format: Print the number of indices i from 1 through n-2 with a[i]>a[i-1] and a[i]>a[i+1]. Constraints: 1 <= n <= 100000; -10^9 <= values <= 10^9

Example 1:

Input: 7 1 3 2 4 6 1 5
Output: 2

Example 2:

Input: 3 1 2 1
Output: 1

Example 3:

Input: 5 1 2 3 4 5
Output: 0

Constraints:

1 <= n <= 100000; -10^9 <= values <= 10^9

Tags:

arrays neighbor-comparison
Loading...
Test Cases:No test cases
No test cases available.
Count the Local High Points - EASY Coding Problem | CodeTikki