Developer

This experience deserves a bigger screen

The DSA Visualizer is designed for deep focus,
side-by-side code, and real-time execution insight.

On small screens, that level of clarity can't be preserved.

Open on a tablet (landscape) or desktop for the intended experience.

Desktop experience preview

Find Peak ElementStep-by-Step Visualization

A peak element is an element that is strictly greater than its neighbors. This problem can be solved in logarithmic time using binary search logic.

Problem Statement

A peak element is an element that is strictly greater than its neighbors. Given a 0-indexed integer array nums, find a peak element, and return its index. If the array contains multiple peaks, return the index to any of the peaks.

Approach

Binary search. If nums[mid] < nums[mid+1], we are on an uphill slope, so the peak must be to the right (left = mid + 1). Otherwise, we are on a downhill slope or at a peak, so search left (right = mid).

Time & Space Complexity

Time complexity is O(log n). Space complexity is O(1).

Interactive Visualization

Loading Interactive Visualizer...

Click "Play" or use arrow keys to step through the execution.