Longest Continuous Increasing Subsequence
1 approach, code in every language
Problem description
Given an integer array, find the length of the longest run of elements that is strictly increasing and unbroken, meaning the chosen elements must sit next to each other in the original order. Ties in value break the streak, so equal neighbours cannot be part of the same run.
You can think of it as a window that keeps growing while each new element is larger than the one before it, and collapses back to size one the instant that rule is violated.
Example 1
Input: nums = [1,3,5,4,7]
Output: 3
The run 1,3,5 climbs for three elements before 4 breaks the streak; 4,7 only reaches length two.
Example 2
Input: nums = [2,2,2,2]
Output: 1
No neighbour is strictly larger than the previous one, so the longest strictly increasing run is a single element.
Constraints
1 ≤ nums.length ≤ 10^4-10^9 ≤ nums[i] ≤ 10^9
Create a free account to see the solution
You get the step-by-step animation, the intuition and clean code in every language. Free, no credit card.
After the pattern
Now solve one you haven't seen.
Longest Rising Run of Gauge Readings is our own problem on the technique behind Longest Continuous Increasing Subsequence: a new statement, so there's no answer to remember. Write it in your browser and run it against graded tests.
1,194 problems · 15,062 graded tests · free