# 852. Peak Index in a Mountain Array

![](https://4272748102-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LekNH5IywF8mjBxFcnu%2F-MivTTW-Ph-JTm7lnn3V%2F-MivTjRv2l-0UoSeE74s%2Fimage.png?alt=media\&token=127c3d8d-7668-433e-9317-279f16574723)

![](https://4272748102-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LekNH5IywF8mjBxFcnu%2F-MivTTW-Ph-JTm7lnn3V%2F-MivTmyfh3Uhjfn5P2vX%2Fimage.png?alt=media\&token=67fb4e31-6d5c-47f1-8445-4d456c0f0f5d)

![](https://4272748102-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LekNH5IywF8mjBxFcnu%2F-MivTTW-Ph-JTm7lnn3V%2F-MivTrfWyl2pQb8-F6yl%2Fimage.png?alt=media\&token=c6f87f57-6e57-4e87-ae06-9610fe991e08)

time: O(logn)

space: O(1)

```java
class Solution {
    public int peakIndexInMountainArray(int[] arr) {
        int start = 0;
        int end = arr.length - 1;
        
        while (start + 1 < end) {
            int mid = start + (end - start)/2;
            if (arr[mid] < arr[mid+1]) {
                start = mid;
            } else {
                end = mid;
            }
        }
        return Math.max(start, end);
    }
}
```
