Problems > Find the Peak

Find the Peak

Difficulty: 1400 3000 ms 128 MB

binary-search

The array strictly increases to a single peak and then strictly decreases (either side may be empty). Print the 1-based index of the peak.

Input: the first line has N; the second line has the mountain array.

Output: the peak's position.

Constraints:

  • 1 ≤ N ≤ 105

Sample Tests

Input 1
5
1 3 5 4 2
Output 1
3
Input 2
3
3 2 1
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.