#K89962. Find Array Peaks
Find Array Peaks
Find Array Peaks
Given an array of integers, your task is to identify all the peaks in the array. An element at index \(i\) is considered a peak if it is strictly greater than its immediate neighbors. Formally, an index \(i\) (with \(1 \leq i \leq n-2\)) is a peak if
\(a_i > a_{i-1} \quad \text{and} \quad a_i > a_{i+1}\)
Output the total number of peaks found and list each peak with its value and index (0-indexed) in the order in which they appear in the array.
inputFormat
The first line of input contains a single integer n
representing the number of elements in the array.
The second line contains n
space-separated integers which are the elements of the array.
outputFormat
Print the number of peaks found on the first line.
If at least one peak exists, then for each peak, print a line with two space-separated integers: the peak's value and its index.
## sample7
1 3 5 4 2 6 3
2
5 2
6 5
</p>