An array arr a mountain if the following properties hold:


	arr.length &gt;= 3
	There exists some i with 0 &lt; i &lt; arr.length - 1 such that:
	
		arr[0] &lt; arr[1] &lt; ... &lt; arr[i - 1] &lt; arr[i] 
		arr[i] &gt; arr[i + 1] &gt; ... &gt; arr[arr.length - 1]
	
	


Given a mountain array arr, return the index i such that arr[0] &lt; arr[1] &lt; ... &lt; arr[i - 1] &lt; arr[i] &gt; arr[i + 1] &gt; ... &gt; arr[arr.length - 1].

You must solve it in O(log(arr.length)) time complexity.

&nbsp;
Example 1:

Input: arr = [0,1,0]
Output: 1


Example 2:

Input: arr = [0,2,1,0]
Output: 1


Example 3:

Input: arr = [0,10,5,2]
Output: 1


&nbsp;
Constraints:


	3 &lt;= arr.length &lt;= 105
	0 &lt;= arr[i] &lt;= 106
	arr is guaranteed to be a mountain array.


class Solution:
    def peakIndexInMountainArray(self, arr: List[int]) -> int:
        beg = 0
        end = len(arr)-1
        
        while beg <= end:
            mid = (beg+end)//2
            if arr[mid] < arr[mid+1]:
                beg = mid +1
            elif arr[mid] > arr[mid+1]:
                end = mid -1
        return beg
class Solution {
public int peakIndexInMountainArray(int[] arr) {

    int start = 0;
    int end = arr.length - 1;

    while( start < end){
        int mid = start + (end - start)/2;
        // if mid < mid next
        if(arr[mid] < arr[mid + 1]){
            start = mid + 1;
        }
        // otherwise it can either peak element or greater element
        else{
            end = mid;
        }
    }
    return start; // or we can return end also, bcz both will be on same value at the time, that's why loop breaks here.
    }
}
class Solution {
public:
    int peakIndexInMountainArray(vector<int>& arr) {
        return max_element(arr.begin(), arr.end()) - arr.begin();
    }
};
var peakIndexInMountainArray = function(arr) {

    //lets assume we have peak it divides array in two parts
    // first part is increasing order , second part is decreasing
    // when we find the middle we'll compare arr[middle] > arr[middle+1], it means
    //we can only find max in first part of arr (increasing part) else second part.
    //there will be point where start === end that is our peak
    let start = 0;
    let end = arr.length -1;
    while(start < end){
        let mid = parseInt(start + (end - start)/2)
        if( arr[mid] > arr[mid + 1]){
            end = mid;
        }else {
            start = mid +1;
        }
    }

    return start;

};
Peak Index in a Mountain Array