Longest Climbing Streak

Easy1-D Dynamic Programming

Problem

A hiker logs the altitude at each checkpoint in alts. A climbing streak is a run of consecutive checkpoints where every altitude is strictly higher than the one before.

Return the length of the longest climbing streak. A single checkpoint is a streak of length 1; an empty log has length 0.

Example 1

Input:
alts = [3, 4, 8, 2, 5, 9, 11, 1]
Output:
4

2 → 5 → 9 → 11 is the longest run of strict increases.

Example 2

Input:
alts = [5, 5, 5]
Output:
1

Equal altitudes do not count as climbing.

Constraints

  • 0 ≤ alts.length ≤ 10^5
  • -10^9 ≤ alts[i] ≤ 10^9

Hint

Show the first hint

What is the longest climbing streak that ends exactly at checkpoint i?

Walkthrough

How to approach it

01Clarify before coding

  • Strict or non-strict increase? Strict: equal neighbours break the streak.
  • Contiguous or any subsequence? Contiguous checkpoints only (the subsequence version is a different, harder problem).
  • Can the log be empty? Yes: return 0.

02Brute force

For every start i, extend j while alts[j] > alts[j - 1] and record the longest run.

Cost: O(n²) in the worst case (a fully increasing array restarts the scan from every index): 5·10^9 steps for n = 10^5.

The rest of the walkthrough is in the app

The full walkthrough (key insight, step-by-step, dry run, complexity, edge cases, pitfalls, follow-ups) and solutions in Python and JavaScript are in the app, next to an editor and a terminal that runs your code against the tests.

This problem is part of Pro.