#C11975. Find the Peak Elements

    ID: 41350 Type: Default 1000ms 256MiB

Find the Peak Elements

Find the Peak Elements

Given an array of integers, identify all the peak elements in the array. An element \( a_i \) is considered a peak if one of the following conditions holds:

  • If the array contains only one element, then it is a peak.
  • If it is the first element and \( a_i > a_{i+1} \).
  • If it is the last element and \( a_i > a_{i-1} \).
  • If it is in the middle and \( a_i > a_{i-1} \) and \( a_i > a_{i+1} \).

Your task is to output the peaks for each test case. If a test case does not have any peak elements, output an empty line.

inputFormat

The input is read from standard input. The first line contains a single integer \( T \) indicating the number of test cases. Each test case consists of two lines:

  1. The first line of each test case contains an integer \( N \), the size of the array.
  2. The second line contains \( N \) space-separated integers representing the elements of the array.

outputFormat

For each test case, print a single line containing the peak elements separated by a single space. If there are no peak elements for that test case, print an empty line.

## sample
2
6
1 3 2 7 9 6
5
10 20 15 2 23
3 9

20 23

</p>