AAlgoLoopSpaced repetition for LeetCode
EASYSliding WindowLeetCode ↗

Longest Continuous Increasing Subsequence

The key idea

A continuous increasing run can only ever be extended by one position to its right. Walk the array once, growing the current run length whenever nums[i] > nums[i-1] and resetting it to 1 at every break, tracking the longest run seen.

Problem

Given an unsorted array of integers nums, return the length of the longest continuous increasing subsequence (that is, a subarray of consecutive positions).

A continuous increasing subsequence is defined by two indices l and r (with l <= r) such that the subarray nums[l], nums[l + 1], ..., nums[r] is strictly increasing — every element is greater than the one before it — and for any index i in the range l <= i < r, the condition nums[i] < nums[i + 1] holds. The subsequence must occupy adjacent positions in the original array, so it cannot skip over elements.

Constraints

Examples

Input: nums = [1,3,5,4,7] Output: 3
Input: nums = [2,2,2,2,2] Output: 1

Complexity

Time: O(n) Space: O(1)

See the full solution

410310
Step-by-step visualization
Start free →

More Sliding Window problems