Find Peak Element

Med
Concept
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start to step? all shortcuts

Solution Guide: Find Peak Element

Approach

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.

Complexity Analysis

Time
O(log n)
Space
O(1)

Pattern

Binary Search (Boundary Finding)

Why It Works

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