Find the Summit of a Mountain Array
A mountain array is an array of integers where the values first rise continuously from the start, then fall continuously to the end. Formally, an integer array heights of length n is a mountain array if there exists a peak index p where 1 <= p <= n - 2 such that:
heights[0] < heights[1] < ... < heights[p]heights[p] > heights[p + 1] > ... > heights[n - 1]
Every mountain array has exactly one peak index, and it is never the first or the last element.
A survey team recorded the elevation of a mountain along a straight east-west transect. The readings strictly increase as the path climbs, reach the highest point, then strictly decrease along the descent. Team members want to know which position holds the summit so they can plant a flag. Scanning every reading is fine in the field, but for a very long ridge it is far smarter to hone in on the summit with a guided search, halving the searchable span at every step.
Given a mountain array heights, return the peak index p such that heights[p] is the maximum value in the array.
Your algorithm must run in O(log n) time, where n is the length of heights.
Find the Summit of a Mountain Array
A mountain array is an array of integers where the values first rise continuously from the start, then fall continuously to the end. Formally, an integer array `heights` of length `n` is a mountain array if there exists a peak index `p` where `1 <= p <= n - 2` such that: