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
- 1 <= nums.length <= 10^4
- -10^9 <= nums[i] <= 10^9
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
- ✓Full worked approach
- ✓Reference code in 5 languages
- ✓Problem-solving tips
- ✓Step-by-step animated visualization
More Sliding Window problems
- Find All Anagrams in a StringMEDIUM
- Longest Repeating Character ReplacementMEDIUM
- Longest Subarray of 1's After Deleting One ElementMEDIUM
- Longest Substring Without Repeating CharactersMEDIUM
- Max Consecutive Ones IIIMEDIUM
- Maximum Average Subarray IEASY
- Maximum Number of Vowels in a Substring of Given LengthMEDIUM
- Minimum Size Subarray SumMEDIUM
- Minimum Window SubstringHARD
- Permutation in StringMEDIUM
- Sliding Window MaximumHARD
- Substring with Concatenation of All WordsHARD