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
๐Ÿ“ˆ Finding Longest Stock Price Increase StreakPriceDays$1$3$2$4$5$6โ†— +2โ†˜ -1Longest Streak: 4 days!๐Ÿ’ก Key Insight:Track current streak length and maximum streak simultaneously in one pass!
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

n
2n
โœ“ Linear Growth
Space Complexity
O(1)

Only using two integer variables to track lengths

n
2n
โœ“ Linear Space

Constraints

  • 0 โ‰ค nums.length โ‰ค 104
  • -109 โ‰ค nums[i] โ‰ค 109
  • The subsequence must be strictly increasing (no equal elements)
Asked in
Facebook 25 Google 18 Amazon 15 Microsoft 12
28.5K Views
Medium Frequency
~12 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
๐Ÿ’ก Explanation
AI Ready
๐Ÿ’ก Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen