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
Compare mid to its right neighbor. If the right neighbor is larger, a peak must exist to the right (uphill). If mid is larger, a peak exists at mid or to the left. Converge left and right until they meet at a peak.
If the right neighbor is larger, climbing right guarantees a peak exists there (array drops to -infinity at boundaries). Same logic applies for left. Always move toward the uphill direction.
Updated Feb 2026