#C6322. Find the Peak Element in a Mountain Array
Find the Peak Element in a Mountain Array
Find the Peak Element in a Mountain Array
You are given a mountain array, which is defined as an array (A) that increases strictly until a peak index and then decreases strictly. Formally, there exists an index (i) ( (0 < i < n-1) ) such that (A[0] < A[1] < \cdots < A[i]) and (A[i] > A[i+1] > \cdots > A[n-1]). Your task is to find and return the index of the peak element. It is guaranteed that the input array is a valid mountain array.
inputFormat
The input is read from standard input (stdin) and consists of two lines. The first line contains a single integer (n) representing the number of elements in the mountain array. The second line contains (n) space-separated integers, which are the elements of the array.
outputFormat
Print a single integer to standard output (stdout), which is the index of the peak element in the mountain array.## sample
5
0 2 5 3 1
2