#K66272. Count Unobstructed Views
Count Unobstructed Views
Count Unobstructed Views
Given a sequence of building heights, determine how many buildings have an unobstructed view. A building is said to have an unobstructed view if there is no building to its right that is taller than it. Formally, for an array of heights ( a_1, a_2, \dots, a_n ), a building at position ( i ) has an unobstructed view if ( a_i > \max{a_{i+1}, a_{i+2}, \dots, a_n} ).
For example, if the building heights are [3, 7, 8, 3, 6, 1], then the buildings with heights 8, 7, and 3 (the leftmost one) have unobstructed views, so the answer is 3.
inputFormat
The input is given from standard input (stdin).
The first line contains an integer ( n ) which represents the number of buildings.
The second line contains ( n ) space-separated integers, each representing the height of a building.
outputFormat
Print a single integer to standard output (stdout), which is the number of buildings that have an unobstructed view.## sample
6
3 7 8 3 6 1
3