Peak Index in a Mountain Array
mediumTime: O(log n)Space: O(1)
Signals to notice
peak of mountain arraygoes up then downbinary search on slope
Brute force first
Linear scan for max — O(n).
The key insight
Binary search: if nums[mid] < nums[mid+1], ascending (peak right). Else descending (peak left/at mid). O(log n).
What must stay true
The array is bitonic. Comparing mid with mid+1 determines which slope you're on.
Easy way to go wrong
Comparing with both neighbors — only mid vs mid+1 is needed.