Watch 10 video solutions for Longest Continuous Increasing Subsequence, a easy level problem involving Array. This walkthrough by Nick White has 41,843 views views. Want to try solving it yourself? Practice on FleetCode or read the detailed text solution.
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].
Example 1:
Input: nums = [1,3,5,4,7] Output: 3 Explanation: The longest continuous increasing subsequence is [1,3,5] with length 3. Even though [1,3,5,7] is an increasing subsequence, it is not continuous as elements 5 and 7 are separated by element 4.
Example 2:
Input: nums = [2,2,2,2,2] Output: 1 Explanation: The longest continuous increasing subsequence is [2] with length 1. Note that it must be strictly increasing.
Constraints:
1 <= nums.length <= 104-109 <= nums[i] <= 109Problem Overview: Given an integer array nums, find the length of the longest strictly increasing continuous subarray. The sequence must use adjacent elements, so you cannot skip indices like in the classic LIS problem.
Approach 1: Sliding Window (O(n) time, O(1) space)
Treat the array as a window that expands while elements remain strictly increasing. Maintain two pointers: start marks the beginning of the current increasing window and i scans through the array. If nums[i] > nums[i-1], the window continues growing. When the order breaks, move start to i because a new increasing segment begins. Track the maximum window length seen during the scan.
This works because a continuous increasing sequence only depends on the relationship between adjacent elements. The moment the condition fails, the previous window cannot extend further. The algorithm performs a single pass over the array, making it efficient for large inputs. This pattern is common in problems involving consecutive segments and appears frequently in sliding window problems.
Approach 2: Greedy Linear Scan (O(n) time, O(1) space)
A simpler variation uses a greedy counter instead of explicit window pointers. Maintain two variables: currentLength for the current increasing run and maxLength for the best result so far. Iterate from index 1 to the end. If nums[i] > nums[i-1], increment currentLength. Otherwise reset it to 1 because the sequence must restart from the current element.
The greedy insight: at each step, extending the current increasing run is always optimal if the condition holds. There is no benefit in restarting earlier or skipping elements because the subsequence must remain continuous. This keeps the logic minimal while still achieving optimal performance. The approach is often discussed alongside basic array traversal patterns and greedy techniques.
Recommended for interviews: The greedy single-pass scan is typically what interviewers expect. It shows you recognize that only adjacent comparisons matter and that the problem reduces to tracking streak lengths. Explaining the sliding window interpretation first can demonstrate problem decomposition, but implementing the greedy version quickly signals strong pattern recognition.
| Approach | Time | Space | When to Use |
|---|---|---|---|
| Sliding Window | O(n) | O(1) | Useful when thinking in terms of continuous segments or adapting to other window-based problems |
| Greedy Linear Scan | O(n) | O(1) | Best general solution; minimal code and optimal performance for interviews |