A hiker's altimeter records one elevation reading at every checkpoint along a trail, in the order the checkpoints were reached. Call a stretch of the trail a clean ascent if it consists of one or more consecutive checkpoints such that every reading in the stretch is strictly greater than the reading immediately before it. Given the full log of readings for the trail, find the length, in checkpoints, of the longest clean ascent anywhere in the log.
n, the number of checkpoints.n integers, the elevation readings in the order the checkpoints were visited.Print a single integer: the length of the longest clean ascent.
1 <= n <= 10^5-10^4 <= reading <= 10^4Example 1
Input
6 10 20 15 16 18 25
Expected
4
Explanation
The readings 10, 20 form an ascent of length 2, then 15 breaks it since 15 is not greater than 20. From 15 onward, 15, 16, 18, 25 is strictly increasing all the way to the end, giving an ascent of length 4, which is the longest, so the answer is 4.
Example 2
Input
4 9 7 5 3
Expected
1
Explanation
Every reading is smaller than the one before it, so no two consecutive checkpoints form an ascent; the longest clean ascent is a single checkpoint on its own, giving length 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 →