visual walkthrough
Find Peak Element
Binary search without sorted data, guided by the slope.
The idea
Any peak will do. Picture the edges as holes (−∞): walking uphill from anywhere must end at a peak.
So look at the slope at mid and keep the uphill side. That side always contains a peak.
Complexity
| approach | time | space |
|---|---|---|
| Walk until it drops | O(n) | O(1) |
| Binary search on the slope | O(log n) | O(1) |