#K11736. Peak Element Finder
Peak Element Finder
Peak Element Finder
You are given an array of integers. A peak element is an element that is strictly greater than its neighbors. For the first and last elements, consider only one neighbor. Your task is to find the index of any peak element. The expected algorithm should run in (O(\log n)) time using binary search.
Input is read from standard input (stdin) and output is written to standard output (stdout).
inputFormat
The first line contains a single integer (n) ((n \ge 1)), representing the number of elements in the array. The second line contains (n) space-separated integers.
outputFormat
Output a single integer which is the index of any peak element. Note that if there are multiple peak elements, any valid index is accepted.## sample
5
1 2 3 1 0
2