Given an array arr, return the index of the largest element. The intended use is a mountain array (strictly increasing then strictly decreasing), where the answer is the index of the peak; the function should also work when the array is purely increasing (peak is the last index).
Input
arr: an array of integers with at least one element
Output
The index of the maximum element under the binary-search comparison rule (move toward the side that increases).
Examples
Example 1
Inputarr = [1, 2, 3, 4, 5]
Output4
Example 2
Inputarr = [10, 20]
Output1
Constraints
1 <= arr.length
Solve in O(log n) time using binary search.