Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Because the array increases then decreases, compare mid with mid+1. If rising, peak is to the right; if falling, peak is at mid or to the left.
The mountain shape guarantees a directional slope. Each step moves toward the slope change, so left/right bounds narrow until only the peak index remains.
Updated Feb 2026