#K35292. Buildings with a Sunset View
Buildings with a Sunset View
Buildings with a Sunset View
You are given a direction and a list of building heights. The direction is specified by a character, either W
(west to east) or E
(east to west). Imagine the sun sets in the specified direction. A building has a sunset view if it is taller than all the buildings that come before it in the viewing order.
Formally, let the list of building heights be \( h_1, h_2, ..., h_n \). For direction W
, a building \( h_i \) has a sunset view if \( h_i > \max\{h_1, h_2, \ldots, h_{i-1}\} \) (with an empty set for the first building, so it always has a view if it exists). For direction E
, the viewing order is reversed. Your task is to compute the number of buildings that have a sunset view.
Input is provided via stdin and output should be printed to stdout.
inputFormat
The input consists of two lines:
- The first line contains a single character
W
orE
representing the direction from which to view the buildings. - The second line contains zero or more space-separated integers representing the heights of the buildings.
If there are no buildings, the second line will be empty.
outputFormat
Output a single integer representing the number of buildings with a sunset view.
## sampleW
7 4 8 2 9 5
3