#C3168. First Peak Element
First Peak Element
First Peak Element
You are given an array of integers. Your task is to find the first peak element in the array. An element is considered a peak if it is strictly greater than its adjacent neighbors. For the first and last elements, you only need to compare with the single neighbor they have.
Formally, for an element a[i]
to be a peak, it must satisfy:
If no peak element exists in the array, output -1
.
Note: If the array contains only one element, that element is considered the peak.
inputFormat
The first line of the input contains an integer n
representing the number of elements in the array. The second line contains n
space-separated integers which form the array.
outputFormat
Output a single integer: the first peak element found in the array. If no such element exists, output -1
.
1
5
5
</p>