The Peak Index in a Mountain Array problem gives you a mountain array — values strictly increase to a peak, then strictly decrease — and asks for the index of the peak element. This coding problem applies binary search to find the peak in O(log n). The array and binary search interview pattern is demonstrated.
Microsoft, Meta, Amazon, Google, and Bloomberg ask this as a standard binary search variant. It tests whether candidates can adapt binary search to "find the peak" by comparing middle elements with their neighbors to determine which half contains the peak.
Binary search on slope. At any index mid: if arr[mid] < arr[mid+1], the peak is to the right (ascending slope). If arr[mid] > arr[mid+1], the peak is to the left (descending slope). Adjust lo and hi accordingly. When lo == hi, that's the peak index.
arr=[0,2,5,3,1]. lo=0, hi=4.
Mountain array peak finding is a gateway to harder binary search problems. The key: use the slope direction (arr[mid] vs arr[mid+1]) to determine which half to search. This same technique applies to "find peak in 2D matrix," "find peak with duplicates," and "search in rotated array." Practice the slope-based binary search template until it's intuitive.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Search in Rotated Sorted Array II | Medium | Solve | |
| Maximum Candies Allocated to K Children | Medium | Solve | |
| Minimum Limit of Balls in a Bag | Medium | Solve | |
| Minimum Number of Days to Make m Bouquets | Medium | Solve | |
| Find the Smallest Divisor Given a Threshold | Medium | Solve |