Longest Continuous Increasing Subsequence - Problem
You're given an unsorted array of integers nums, and your task is to find the length of the longest continuous increasing subsequence (also known as a subarray).
A continuous increasing subsequence is a contiguous portion of the array where each element is strictly greater than the previous element. For example, in the array [1, 3, 2, 4, 5, 6], the longest continuous increasing subsequence is [2, 4, 5, 6] with length 4.
Key Points:
- The subsequence must be continuous (adjacent elements in the original array)
- Each element must be strictly greater than the previous one
- Return the length, not the actual subsequence
This problem tests your ability to efficiently traverse an array while tracking streaks of increasing values.
Input & Output
example_1.py โ Basic Increasing Sequence
$
Input:
[1,3,6,7]
โบ
Output:
4
๐ก Note:
The entire array forms one continuous increasing subsequence: 1 < 3 < 6 < 7. Length = 4.
example_2.py โ Mixed Sequence
$
Input:
[2,2,2,2,2]
โบ
Output:
1
๐ก Note:
All elements are equal, so no increasing subsequence of length > 1 exists. Each element forms a subsequence of length 1.
example_3.py โ Multiple Increasing Segments
$
Input:
[1,3,2,4,5,6]
โบ
Output:
4
๐ก Note:
We have two increasing subsequences: [1,3] (length 2) and [2,4,5,6] (length 4). The longest has length 4.
Visualization
Tap to expand
Understanding the Visualization
1
Start tracking
Begin with day 1, current streak = 1 day
2
Price increases
When price goes up, extend the streak
3
Price decreases
When price drops, start a new streak
4
Keep best record
Always remember the longest streak found
Key Takeaway
๐ฏ Key Insight: We don't need to check all possible combinations - just track the current increasing streak and remember the longest one we've seen!
Time & Space Complexity
Time Complexity
O(n)
Single pass through the array, checking each element once
โ Linear Growth
Space Complexity
O(1)
Only using two integer variables to track lengths
โ Linear Space
Constraints
- 0 โค nums.length โค 104
- -109 โค nums[i] โค 109
- The subsequence must be strictly increasing (no equal elements)
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code