#K67437. Ocean View Buildings
Ocean View Buildings
Ocean View Buildings
You are given n buildings in a line, each with a certain height. The buildings are given in order from left to right. A building has an ocean view if all the buildings to its right have a lower height than it. Formally, let \( h_i \) denote the height of the \( i\text{-th} \) building; then the building at position \( i \) has an ocean view if for every \( j > i \), \( h_j < h_i \).
Your task is to determine the number of buildings that have an ocean view.
Note: If there are no buildings (i.e. \( n = 0 \)), output 0.
inputFormat
The input is read from standard input and consists of two lines:
- The first line contains a single integer ( n ) representing the number of buildings.
- The second line contains ( n ) space-separated integers representing the height of each building from left to right.
For example:
5 1 3 2 4 2
outputFormat
Output a single integer to standard output: the number of buildings with an ocean view.## sample
6
4 2 3 1 5 4
2