Top of the Mountain
A trail's heights are written in the list heights, one per marker. The trail climbs strictly to a single peak and then falls strictly to the end: every height before the peak is lower than the next one, and every height after it is lower than the one before.
Return the index of the peak. The peak is never the first or the last marker.
Examples
heights = [1, 4, 9, 7, 2] → 2
heights = [0, 10, 5] → 1
heights = [2, 3, 4, 5, 1] → 3
heights = [1, 9, 8, 7, 6] → 1Constraints
- Between 3 and 100,000 heights, each between 0 and 1,000,000,000, climbing to one peak and then falling.
- Aim for O(log n): a trail four times longer should take only a couple of steps more.
Console
›Run to see what your code prints
Run checks the 4 visible cases here, in your browser. Submit runs all 8 on the judge, 4 of them hidden, and measures how your solution scales.
Expected is the reference solution's answer, from the judge. An input that breaks the statement's other rules may get any answer.