#K39612. Find the First Peak in Temperature Records
Find the First Peak in Temperature Records
Find the First Peak in Temperature Records
You are given a list of integer temperature records. A peak is defined as an element in the list that is greater than its immediate neighbors. Specifically, an element \(a_i\) is considered a peak if:
- For \(i = 0\) (the first element), if \(a_0 > a_1\), it is a peak.
- For \(i = n-1\) (the last element), if \(a_{n-1} > a_{n-2}\), it is a peak.
- For any other index \(0 < i a_{i-1}\) and \(a_i > a_{i+1}\), it is a peak.
Your task is to identify and print the first peak element in the given list. If no peak exists, output \(-1\).
inputFormat
The input is given via standard input (stdin). The first line contains an integer \(n\) representing the number of temperature records. The second line contains \(n\) space-separated integers representing the temperature records. If \(n = 0\), the list is empty.
outputFormat
Output the first peak element to standard output (stdout). If no peak exists, output \(-1\).
## sample8
1 3 2 4 5 3 7 2
3