#K34142. Sunset View
Sunset View
Sunset View
You are given a list of building heights. A building has a view of the sunset if there are no taller buildings to its right. The sun sets in the west and thus only buildings on the far right or buildings not blocked by any taller building to their right can see the sunset.
Your task is to determine and output the indices (0-indexed) of all buildings that have a sunset view, in increasing order.
Mathematically, if the list of building heights is represented as \(h_0, h_1, \dots, h_{n-1}\), then a building at index \(i\) has a sunset view if \(h_i > \max\{h_{i+1}, h_{i+2}, \dots, h_{n-1}\}\). If there are no buildings on the right (i.e. for the last building), it always has a view.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains an integer \(n\) representing the number of buildings. \(n\) can be zero.
- If \(n > 0\), the second line contains \(n\) space-separated integers, where each integer represents the height of a building.
outputFormat
Output to standard output (stdout) the 0-indexed indices of the buildings that can see the sunset. The indices should be output in increasing order, separated by a single space. If no building has a view (i.e. when \(n = 0\)), output nothing.
## sample4
4 2 3 1
0 2 3