#C11389. Visible Flags on Buildings
Visible Flags on Buildings
Visible Flags on Buildings
You are given n buildings in a row, each with a certain height. A flag can be placed on a building if its height is strictly greater than the height of every building to its left. Formally, let the heights be represented as an array \(a_1, a_2, \dots, a_n\). A flag is placed on building \(i\) if
\(a_i > \max\{a_1, a_2, \dots, a_{i-1}\}\)
with the convention that the first building always gets a flag since there are no buildings to its left. Your task is to compute the total number of flags placed.
Example:
Input: n = 5, heights = [4, 3, 2, 5, 1] Output: 2
Explanation: The flag can be placed on the 1st building (4) and the 4th building (5) because for each, its height is greater than every building before it.
inputFormat
The input consists of two lines:
- The first line contains an integer \(n\) representing the number of buildings.
- The second line contains \(n\) space-separated integers that represent the heights of the buildings.
outputFormat
Output a single integer: the number of buildings on which a flag can be placed.
## sample5
4 3 2 5 1
2