#K40317. Find the Closest Peak Point

    ID: 26616 Type: Default 1000ms 256MiB

Find the Closest Peak Point

Find the Closest Peak Point

You are given a list of integers and a number key. Your task is to find the index of the first peak point in the list which is strictly greater than key.

A peak point is defined as follows:

  • For the first element (index 0): it is a peak point if \(a_0 > a_1\).
  • For the last element (index \(n-1\)): it is a peak point if \(a_{n-1} > a_{n-2}\).
  • For all other elements at index \(i\) (\(0 < i < n-1\)): it is a peak point if \(a_i > a_{i-1}\) and \(a_i > a_{i+1}\).

You must only consider those peak points that have a value strictly greater than the given key and return the index of the first valid candidate encountered. If no such peak point exists, output -1.

Note: The input is given via standard input and the output should be printed to standard output.

inputFormat

The first line contains an integer n representing the number of elements in the array.

The second line contains an integer key.

The third line contains n space-separated integers representing the elements of the array.

Constraints: It is guaranteed that n \ge 1.

outputFormat

Output a single integer which is the index of the first peak point in the array that is strictly greater than key. If no such peak point exists, output -1.

## sample
7
18
5 10 20 15 7 25 30
2

</p>