#K61712. Find Local Maxima Indices
Find Local Maxima Indices
Find Local Maxima Indices
You are given a list of integers. Your task is to identify all local maxima in the list and output their indices. An element of the list (with index \(i\)) is considered a local maximum if it satisfies:
[ A[i] > A[i-1] \quad \text{and} \quad A[i] > A[i+1] ]
Note that the first and last elements of the list cannot be local maxima because they do not have two neighbors.
Example 1:
Input: 7 1 3 2 4 1 5 1 Output: 1 3 5
Example 2:
Input: 5 1 2 3 4 5 Output:
inputFormat
The input is given via standard input (stdin) and consists of two lines:
- The first line contains a single integer \(n\) representing the number of elements in the list.
- The second line contains \(n\) space-separated integers.
outputFormat
Output the indices (0-indexed) of all local maxima on a single line, separated by a space. If there are no local maxima, output an empty line.
## sample7
1 3 2 4 1 5 1
1 3 5