← Back

⛰️ Peak Summit Expedition

Find Peak Element in Mountain Array

Mid Value

-

Mid+1 Value

-

Direction

-

Peak Found

?

Steps

0
πŸ”‘ Key Insight
If arr[mid] > arr[mid+1] β†’ Peak is on LEFT (including mid)
If arr[mid] < arr[mid+1] β†’ Peak is on RIGHT
⛰️ The Mountain Range ⛰️
L: -
M: -
R: -
Generate a mountain to find its peak!

πŸ“– Peak Element Algorithm

Peak: An element greater than its neighbors. arr[i] > arr[i-1] && arr[i] > arr[i+1]

Logic: Compare mid with mid+1 to determine which side has the peak.

Guarantee: If going uphill (mid < mid+1), peak must be ahead. If going downhill, peak is behind or at mid.

Time: O(log n)