#K54037. Count Buildings with a Sunset View

    ID: 29664 Type: Default 1000ms 256MiB

Count Buildings with a Sunset View

Count Buildings with a Sunset View

You are given an array of positive integers representing the heights of a row of buildings from left to right. A building has an unobstructed view of the sunset if it is strictly taller than all the buildings to its left. Formally, a building at position (i) (1-indexed) has a view if [ \text{height}_i > \max{\text{height}_1, \text{height}2, \dots, \text{height}{i-1}}] for (i \geq 1) (with (\max{}) defined as 0 when (i=1)). Your task is to count the number of buildings with an unobstructed sunset view.

Example:
For the input array [7, 4, 8, 2, 9], the buildings with heights 7, 8, and 9 have a view, so the answer is 3.

inputFormat

The input is read from standard input (stdin) and consists of two lines:

  1. The first line contains a single integer (n) representing the number of buildings.
  2. The second line contains (n) space-separated integers, each representing the height of a building.

outputFormat

Print to standard output (stdout) a single integer: the number of buildings which have an unobstructed view of the sunset.## sample

5
7 4 8 2 9
3