Mountain Peak Index

MediumAcc. 94.2%
+30 XP 12

Mountain Ascent

A mountain array strictly increases and then strictly decreases. Find the index of the highest point.

The Assignment

Your function receives arr.

  1. Use Binary Search.
  2. If arr[mid] < arr[mid+1], the peak is on the right.
  3. Else, the peak is this index or on the left.
  4. Print the final index.

01EXAMPLE 1

Input[0, 10, 5, 2]
Output1

Explanation: 10 is at index 1.

Constraints

  • O(log n) time complexity.
ArraysSearching
JavaScript
Loading...
1 Hidden

Input Arguments

arr[0,2,1,0]

Expected Output

1

Click RUN to test your solution