Tap here to switch tabs
Problem
Submissions

Problem: Peak Index in a Mountain Array

med
30 min
Try to solve the Peak Index in a Mountain Array problem.

Statement

Given an integer array arr that is guaranteed to be a mountain array, return the index of its peak element. The peak is the element that is strictly greater than its adjacent elements, where values strictly increase up to the peak and then strictly decrease after it.

Note: A mountain array has some index i such that arr[0] < arr[1] < ... < arr[i] and arr[i] > arr[i+1] > ... > arr[arr.length - 1].

Constraints:

  • 3≤3 \leq arr.length ≤105\leq 10^5

  • 0≤0 \leq arr[i] ≤106\leq 10^6

  • arr is guaranteed to be a mountain array.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Peak Index in a Mountain Array

med
30 min
Try to solve the Peak Index in a Mountain Array problem.

Statement

Given an integer array arr that is guaranteed to be a mountain array, return the index of its peak element. The peak is the element that is strictly greater than its adjacent elements, where values strictly increase up to the peak and then strictly decrease after it.

Note: A mountain array has some index i such that arr[0] < arr[1] < ... < arr[i] and arr[i] > arr[i+1] > ... > arr[arr.length - 1].

Constraints:

  • 3≤3 \leq arr.length ≤105\leq 10^5

  • 0≤0 \leq arr[i] ≤106\leq 10^6

  • arr is guaranteed to be a mountain array.