#K6416. Find Peaks in an Array
Find Peaks in an Array
Find Peaks in an Array
You are given an array of integers. A peak in the array is defined as an element that is not less than its neighbors. For the first and last elements of the array, only one neighbor exists and the element is considered a peak if it is not less than that neighbor.
If the array consists of a single element, then that element is treated as a peak. For arrays of more than one element, the first element is a peak if it is greater than or equal to the second element, and the last element is a peak if it is greater than or equal to the second last element. For any element in the middle (from index 1 to index N-2), it is a peak if it satisfies:
$$a_i \ge a_{i-1} \quad \text{and} \quad a_i \ge a_{i+1}.$$
Your task is to determine and print all the peaks for each test case. The peaks for a test case should be output in the order they appear in the array and separated by a single space.
inputFormat
The input will be read from standard input (stdin) and has the following format:
T N1 a1 a2 ... aN1 N2 a1 a2 ... aN2 ... NT a1 a2 ... aNT
Where T is the number of test cases, and for each test case, the first line contains an integer N representing the number of elements in the array, followed by a line of N space-separated integers.
outputFormat
For each test case, output a single line containing the peaks found in the array. The peaks should be printed in the order in which they appear in the array and separated by a single space. The output should be written to standard output (stdout).
## sample1
1
5
5
</p>