#C4565. Find the Unique Peak Index

    ID: 48117 Type: Default 1000ms 256MiB

Find the Unique Peak Index

Find the Unique Peak Index

You are given an integer (n) and an array (a) of (n) integers. Your task is to determine whether there exists exactly one peak element in the array. A peak element is defined as an element (a_i) (with (2 \le i \le n-1)) that satisfies the condition (a_{i-1} < a_i > a_{i+1}). If there is exactly one such element, output its 1-indexed position; otherwise, output (-1).

For example, in the array [1, 3, 2, 1, 1], the element 3 (at position 2) is a peak because (1 < 3 > 2) and it is the only one. If the array has multiple peaks or none, the output should be (-1).

inputFormat

The input is given via standard input (stdin) and consists of two lines.

The first line contains a single integer (n) (the number of elements in the array).

The second line contains (n) space-separated integers representing the array (a).

outputFormat

Output a single integer: the 1-indexed position of the unique peak element if it exists, otherwise output (-1). The output should be written to standard output (stdout).## sample

5
1 3 2 4 1
-1

</p>