A peak element is an element that is strictly greater than its neighbors.
Given an integer array nums, find a peak element and return its index. If the array contains multiple peaks, return the index to any of the peaks.
You may assume nums[-1] = nums[n] = -∞.
Input: [1,2,3,1] Output: 2
Your program must print a single integer representing the index of any peak element.
No submissions yet.
Discuss binary search optimization and edge cases.