You are given an array of integers, indexed from left to right. An element is called a record high if it is strictly greater than every element that appears before it in the array. The very first element is always a record high (there is nothing before it).
Count how many record highs the array contains.
Line 1: an integer n, the number of elements.
Line 2: n space-separated integers, the array (this line is present whenever n >= 1).
A single integer: the number of record highs.
Example 1
Input
5 3 1 4 1 5
Expected
3
Explanation
Scanning left to right: 3 is a record (first). 1 is not (< 3). 4 is a record (> 3). 1 is not. 5 is a record (> 4). That is 3 record highs.
Example 2
Input
4 7 7 7 7
Expected
1
Explanation
Only the first 7 is a record. The later 7s are equal, not strictly greater, so they do not count. Answer is 1.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →