#K37122. Peak Element Finder
Peak Element Finder
Peak Element Finder
Given an array of integers, your task is to find the index of a peak element. An element is considered a peak if it is greater than its neighbors. Formally, for an index \( i \) (where \( 0 < i < n-1 \)), the element \( a_i \) is a peak if:
\( a_i > a_{i-1} \) and \( a_i > a_{i+1} \).
For the edge cases, the first element is a peak if \( a_0 \geq a_1 \) and the last element is a peak if \( a_{n-1} \geq a_{n-2} \). If there are multiple peaks, output any one of them.
Your solution must read input from standard input and write the result to standard output.
inputFormat
The input contains two lines:
- The first line contains an integer \( n \) indicating the number of elements in the array.
- The second line contains \( n \) space-separated integers representing the array elements.
outputFormat
Output a single integer which is the index (0-indexed) of any peak element in the array.
## sample6
1 3 8 12 4 2
3