#K14406. Find Towers
Find Towers
Find Towers
Given a list of building heights, identify all the "towers" among them. A building is considered a tower if it is strictly taller than its adjacent buildings. Specifically, for a list of length \(n\) with heights \(a_0, a_1, \dots, a_{n-1}\):
- For \(i=0\): it is a tower if \(n=1\) or \(a_0 > a_1\).
- For \(i=n-1\): it is a tower if \(a_{n-1} > a_{n-2}\).
- For \(0 < i a_{i-1}\) and \(a_i > a_{i+1}\).
If no towers exist, output an empty list. The output list should display the tower heights in the same order as they appear in the input.
inputFormat
The first line of input contains an integer (n), representing the number of buildings. The second line contains (n) space-separated integers representing the heights of the buildings.
outputFormat
Output a single line containing the heights of the towers separated by a single space. If there are no towers, output an empty line.## sample
10
1 2 3 1 5 6 2 3 2 1
3 6 3