Loading
Loading
A hiking trail has elevation markers at regular intervals. The trail is strictly unimodal: it climbs strictly to a single highest marker and then descends strictly to the end. Either the climb or the descent may be empty.
Return the index of the highest marker in heights.
heights = [2, 5, 9, 7, 1]lo = 0, hi = 4, mid = 29 > 7: descending at mid, summit is at mid or leftlo = 0, hi = 2, mid = 15 < 9: climbing at mid, summit is right of midlo = 2, hi = 2one candidate left: index 22Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(log n) time · O(1) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
The trail climbs to 9 at index 2, then falls.
Example 2
The trail only descends, so the very first marker is the summit.