#C8913. Find the Highest Peak
Find the Highest Peak
Find the Highest Peak
You are given a mountain range represented as an array of integers. A peak is defined as an element ai that is strictly greater than its two neighbors, i.e. ai > ai-1 and ai > ai+1 for 1 ≤ i ≤ n-2. Your task is to find the position (0-indexed) of the highest peak in the array. If multiple peaks have the same height, output the index of the first occurrence. If there is no peak or there are fewer than 3 elements, output -1.
Formally, given an integer n and an array of altitudes: \(a_0, a_1, \dots, a_{n-1}\), find an index i (1 ≤ i ≤ n-2) such that:
\[ \begin{aligned} a_i > a_{i-1}, \\ a_i > a_{i+1}. \end{aligned} \]and for any other index j that also satisfies the peak condition, ai is maximized. If no such index exists, output -1.
inputFormat
The first line contains an integer n (the number of elements in the array).
The second line contains n space-separated integers representing the altitudes of the mountain range.
outputFormat
Output a single integer: the index of the highest peak. If no peak exists, output -1.
## sample2
1 2
-1
</p>