#C2822. Find Peak Elements
Find Peak Elements
Find Peak Elements
You are given an array of integers of length (n). An element (a_i) is considered a peak if it is strictly greater than its neighbors. For the boundary elements, only one adjacent element is considered and the missing neighbor is treated as (-\infty). In other words, for the first element, it is a peak if (a_0 > a_1), for the last element if (a_{n-1} > a_{n-2}), and for any middle element (where (0 < i < n-1)) if
[ a_i > a_{i-1} \quad \text{and} \quad a_i > a_{i+1} ]
Your task is to find and print all the peak elements in the order they appear in the array.
inputFormat
The input is read from standard input (stdin). The first line contains an integer (n) representing the number of elements in the array. The second line contains (n) space-separated integers representing the array elements.
outputFormat
Print the peak elements to the standard output (stdout) separated by a single space. If no peak elements exist, output an empty line.## sample
1
10
10
</p>