Peak Index in Mountain Array
mediumFind the index of the peak element in a mountain array (strictly increasing then decreasing)
Peak Index in Mountain Array
Key Insight
Compare middle with next element; if it is increasing, peak is right; else peak is at mid or left.
Step 1Setup
Increasing then decreasing
L
R
0
02
13
25
34
41
5Search space: [0..5]
Mountain array [0, 2, 3, 5, 4, 1].
1 / 3