#K78292. Find Peaks in an Array
Find Peaks in an Array
Find Peaks in an Array
You are given an array of integers. A peak is defined as an element that is strictly greater than its neighbors. For an element at index i (0-based), if 0 < i < n-1, then it is a peak if arr[i] > arr[i-1] and arr[i] > arr[i+1]. For the first element (i = 0), it is a peak if it is greater than the second element. For the last element (i = n-1), it is a peak if it is greater than the second-to-last element. If the array contains only one element, that element is considered a peak. Your task is to output the indices of the peaks for each given test case.
inputFormat
The first line of input contains an integer T, the number of test cases. Each test case consists of two lines. The first line contains an integer N, representing the number of elements in the array. The second line contains N space-separated integers denoting the array elements.
outputFormat
For each test case, output a single line containing the 0-based indices of all peak elements separated by a single space. If no peak exists in a test case, print an empty line.## sample
3
5
1 3 2 4 1
6
2 2 2 2 2 2
4
1 2 1 2
1 3
1 3
</p>