eolymp
bolt
Try our new interface for solving problems
Problems

Peak Element

Peak Element

A \textbf{peak element} is an element that is strictly greater than its neighbors. Given a $0$-indexed integer array $a$, find a peak element, and return its index. If the array contains multiple peaks, return the index to any of the peaks. You may imagine that $a_{-1} = a_n = -∞$. In other words, an element is always considered to be strictly greater than a neighbor that is outside the array. \InputFile The first line contains the size of array $n~(n \le 10^6)$. The second line contains **n** integers $a_0, a_1, ... a_{n-1}$. It is known that $|a_i| \le 10^9$ and also that $a_i \ne a_{i + 1}$ for $i = 0, 1, ..., n - 2$. \OutputFile Print the index of a peak element. If the array contains multiple peaks, return the index to any of the peaks.
Time limit 1 second
Memory limit 128 MiB
Input example #1
4
1 2 3 1
Output example #1
2
Input example #2
7
1 2 1 3 5 6 4
Output example #2
1