Find peak element
Your task
A peak element is one strictly greater than its neighbors; out-of-bounds neighbors are treated as negative infinity. Given an integer array nums where no two adjacent elements are equal, return the index of any peak element in O(log n) time. Array length up to 1e5.
Examples
find_peak_element(nums: list[int]) -> intExample 1
Input
find_peak_element([1, 2, 3, 1])Output
2