Ctrl K

Find the Summit

Medium
The array profile describes a mountain: its values strictly increase up to the summit and then strictly decrease. Both the climb and the descent have at least one step. Return the index of the summit (0-based). Scanning the whole array for the maximum is easy; solve it in O(log n).
Example 1
profile=[2, 5, 9, 7, 3] → 2

Heights rise to 9 at position 2 and only fall after it.

Example 2
profile=[0, 4, 1] → 1

The shortest possible mountain: one step up, one step down.

Example 3
profile=[1, 3, 6, 10, 15, 14] → 4
Constraints
  • 3 ≤ len(profile) ≤ 10⁵
  • 0 ≤ profile[i] ≤ 10⁶
  • profile strictly increases up to the summit and strictly decreases after it; the summit is not at either end
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsFind in a Shifted Sorted Array MediumFirst and Last Copy MediumFind in a Row-Chained Grid MediumFind in a Shifted Array With Repeats MediumMinimum of a Shifted List Medium
loading Python…
Input
profile=[2, 5, 9, 7, 3]
Expected
2

Run checks the first 3 tests in your browser. Submit checks all 84 tests on the server, hidden ones included.