To find the peak element in time, think of it as descending or ascending a mountain. If our next item is decreasing, we want to check the left hand side (since that side is higher). Otherwise, our item is equal or increasing, in which case, we want to investigate the right hand side.
class Solution:
def findPeakElement(self, nums: List[int]) -> int:
def bsearch(nums, l, r):
if l == r:
return l
mid = (l + r) // 2
# if numbers are decreasing to the left, go backwards
if nums[mid] > nums[mid + 1]:
return bsearch(nums, l, mid)
# else, search on the right hand side since numbers are increasing as we go up
return bsearch(nums, mid + 1, r)
return bsearch(nums, 0, len(nums) - 1)