Longest Continuous Increasing Subsequence - Problem

Given an unsorted array of integers nums, return the length of the longest continuous increasing subsequence (i.e. subarray). The subsequence must be strictly increasing.

A continuous increasing subsequence is defined by two indices l and r (l < r) such that it is [nums[l], nums[l + 1], ..., nums[r - 1], nums[r]] and for each l <= i < r, nums[i] < nums[i + 1].

Input & Output

Example 1 — Basic Increasing Sequence
$ Input: nums = [1,3,6,7]
Output: 4
💡 Note: The entire array is continuously increasing: 1 < 3 < 6 < 7, so the length is 4
Example 2 — Mixed Sequence
$ Input: nums = [2,2,2,2,2]
Output: 1
💡 Note: All elements are equal, no strictly increasing subsequence longer than 1 exists
Example 3 — Multiple Increasing Parts
$ Input: nums = [1,3,6,2,8]
Output: 3
💡 Note: Longest increasing subsequence is [1,3,6] with length 3. The sequence [2,8] has length 2.

Constraints

  • 1 ≤ nums.length ≤ 104
  • -109 ≤ nums[i] ≤ 109

Visualization

Tap to expand
Longest Continuous Increasing Subsequence INPUT Array nums: 1 i=0 3 i=1 6 i=2 7 i=3 Input Values: nums = [1, 3, 6, 7] Length: 4 elements Goal: Find longest continuous increasing subarray (strictly increasing) ALGORITHM STEPS 1 Initialize count=1, maxLen=1 2 Iterate Array For i=1 to n-1 3 Check Condition If nums[i] > nums[i-1] then count++ 4 Update Max maxLen = max(maxLen, count). Else reset=1 Trace: i=1: 3>1 OK count=2 i=2: 6>3 OK count=3 i=3: 7>6 OK count=4 maxLen = 4 FINAL RESULT Longest Increasing Subsequence Found: 1 3 6 7 1 < 3 < 6 < 7 Output: 4 Entire array is strictly increasing! OK Key Insight: Use single pass O(n) approach: track current streak length and update maximum when streak breaks. When nums[i] <= nums[i-1], reset count to 1. This finds longest CONTINUOUS increasing subarray. TutorialsPoint - Longest Continuous Increasing Subsequence | Optimal Solution O(n)
Asked in
Facebook 35 Apple 28
32.4K Views
Medium Frequency
~15 min Avg. Time
892 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