852. Peak Index in a Mountain Array

PHOTO EMBED

Sun Apr 02 2023 05:45:48 GMT+0000 (Coordinated Universal Time)

Saved by @Ranjan_kumar #c++

class Solution {
public:
    int peakIndexInMountainArray(vector<int>& arr) {
        int st=0, end=arr.size()-1;
        int mid=st+(end-st)/2;
        while(st<=end)
        {
            if(arr[mid]>arr[mid-1]&&arr[mid]>arr[mid+1]) return mid;
            if(arr[mid]<arr[mid+1]) st=mid+1;
            else if(arr[mid]<arr[mid-1]) end=mid;
            mid=st+(end-st)/2;
        }
        return mid;
    }
};
content_copyCOPY

https://leetcode.com/problems/peak-index-in-a-mountain-array/