#C5248. Find Peak Element
Find Peak Element
Find Peak Element
Given an integer array nums
, a peak element is an element that is greater than its neighbors. For the purposes of this problem, you may assume that the elements outside the array boundary are negative infinity, i.e., \(nums[-1] = nums[n] = -\infty\). The array may contain multiple peaks; your task is to return the index of any one of the peak elements.
Your solution should run in logarithmic time complexity, i.e., \(O(\log n)\).
inputFormat
The input consists of two lines. The first line contains a single integer \(n\) representing the number of elements in the array. The second line contains \(n\) space-separated integers, which are the elements of the array.
Example:
4 1 2 3 1
outputFormat
Output a single integer which is the index of a peak element in the array followed by a newline character.
## sample1
1
0
</p>