A peak element is an element that is strictly greater than its neighbors. Return the index of any peak element.
Example 1
Input: nums = [1,3,7,5,9,11,6,4,2]
Output: 2
Explanation: 7 at index 2 is larger than both neighbours (3 and 5), and 11 at index 5 is larger than 9 and 6. Either index is a correct answer.
Example 2
Input: nums = [1,2,3,1]
Output: 2
Explanation: 3 at index 2 is larger than both 2 and 1, so index 2 is a peak.
Example 3
Input: nums = [1,2,1]
Output: 1
Explanation: 2 at index 1 is larger than both neighbours, so index 1 is the peak.
If `nums[mid] < nums[mid+1]`, the right side is "climbing" — there must be a peak to the right (or at `mid+1`). Else there's a peak at `mid` or to the left. That halving rule finds *some* peak in `O(log n)`.
Run checks all cases above. Submit evaluates all test cases.