Find a Peak Element

Medium · Binary Search · about 15 minutes

Asked at Google, Meta, Microsoft, Uber.

A peak element is strictly greater than its neighbors. Given an array nums where adjacent values are never equal, return the index of a peak in O(log n). Imagine nums[-1] = nums[n] = -∞. (The tests here have a single peak, so the answer is unique.)

Related guides