#C10492. Find Peak Element

    ID: 39703 Type: Default 1000ms 256MiB

Find Peak Element

Find Peak Element

Given an array of n unique integers, your task is to find a peak element. An element at index \(i\) is called a peak if it satisfies the following conditions:

  • For \(1 \leq i \leq n-2\): \(A[i] > A[i-1]\) and \(A[i] > A[i+1]\).
  • The first element \(A[0]\) is a peak if \(A[0] > A[1]\).
  • The last element \(A[n-1]\) is a peak if \(A[n-1] > A[n-2]\).

If there are multiple peaks, you may output the index of any one of them. It is guaranteed that the array contains at least one peak element. Note: The indices are 0-indexed.

inputFormat

The input is given via stdin in the following format:

n
A[0] A[1] ... A[n-1]

Where n ((1 \leq n \leq 1000)) is the number of elements in the array and the second line contains n space-separated distinct integers.

outputFormat

Output via stdout a single integer denoting the index of any peak element found in the array.## sample

1
1
0