#K62767. Finding Peaks in a List

    ID: 31605 Type: Default 1000ms 256MiB

Finding Peaks in a List

Finding Peaks in a List

Given a list of integers representing heights, your task is to find all the peaks in the list. An element is considered a peak if it is strictly greater than its immediate neighbors. For the first and last elements, since they have only one neighbor, they are considered peaks if they are greater than that single neighbor.

Special cases:

  • If the list has a single element, treat it as a peak.
  • If all elements are equal, there are no peaks.

The peaks must be output in the order they appear in the list.

inputFormat

The input consists of two lines:

  1. The first line contains an integer n denoting the number of elements in the list.
  2. The second line contains n space-separated integers representing the heights.

outputFormat

Output the peak values in the list separated by a single space. If there are no peaks, output an empty line.

## sample
1
1
1

</p>