#C4467. Find Peak Element
Find Peak Element
Find Peak Element
You are given an array of integers. An element is called a peak element if it is strictly greater than its neighbors. For the first and last elements, you only need to compare with one neighbor. Your task is to find and return any index of a peak element.
The input is given via stdin
and the result should be output to stdout
. Note that the index is 0-based and it is guaranteed that a peak element exists in the array.
Mathematically, for an array \(a[0 \dots n-1]\), an index \(i\) is a peak if:
\[ \begin{cases} a[i] > a[i+1] & \text{if } i = 0, \\ a[i] > a[i-1] & \text{if } i = n-1, \\ a[i] > a[i-1] \text{ and } a[i] > a[i+1] & \text{if } 0 < i < n-1. \end{cases} \]If there are multiple peaks, any one of them is acceptable.
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 array.
outputFormat
Output a single integer representing the index of any peak element.
## sample1
10
0