Talentd
FleetCode
Make and follow sheets.Sign in

Longest Continuous Increasing Subsequence solution and explanation

EasyArray6 min read52.5% acceptanceUpdated 9 Apr 2026
Sliding Window Approach | Longest Continuous Increasing Subsequence | LeetCode 674.Nick White · 7:04 · 41K viewsWatch on YouTube
9 more videos on this problem
  1. Sliding Window Approach | Longest Continuous Increasing Subsequence | LeetCode 674.Nick White · 7:04 · 41K views
  2. 4. Sliding Window | Leetcode | 674 | Longest Continuous Increasing SubsequenceImran Sarwar · 10:48 · 673 views
  3. 674. Longest Continuous Increasing Subsequence Java SolutionCode with Carter · 5:48 · 540 views
  4. LeetCode 674 Longest Continuous Increasing Subsequence (Python)Ran Fang · 6:05 · 472 views
  5. Longest Continuous Increasing Subsequence | Leetcode 674- Amazon Google Facebook interview questionSuper Lazy Coder · 4:59 · 323 views
  6. LeetCode 674. Longest Continuous Increasing Subsequence | JSer - JavaScript & AlgorithmJSer · 2:38 · 278 views
  7. Longest Continuous Increasing Subsequence - Google Interview Question - Leetcode 674The Techie Town · 2:29 · 239 views
  8. Leetcode 674 - Longest Continuous Increasing Subsequence (Python)Hazar Codes · 12:53 · 203 views
  9. 674. Longest Continuous Increasing Subsequence | LEETCODE EASYcode Explainer · 5:19 · 191 views
  10. Leetcode 674: Longest Continuous Increasing Subsequence | JavascriptBINARY LIFE 1100 · 8:26 · 120 views

The 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].

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] <= 109

Approach overview

Problem 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 1: Sliding Window Approach

This approach involves iterating through the array while maintaining a variable to track the length of the current continuous increasing subsequence. As we encounter each element, we check if it is larger than the previous one to decide if we should continue the current subsequence or start a new one. We also maintain a global maximum to store the maximum length found during our iteration.

def find_length_of_LCIS(nums):
    if not nums:
        return 0
    max_len = 1
    curr_len = 1

    for i in range(1, len(nums)):
        if nums[i] > nums[i - 1]:
            curr_len += 1
            max_len = max(max_len, curr_len)
        else:
            curr_len = 1

    return max_len

nums = [1, 3, 5, 4, 7]
print(find_length_of_LCIS(nums))
public class LCIS {
    public static int findLengthOfLCIS(int[] nums) {
        if (nums.length == 0) return 0;
        int maxLen = 1, currLen = 1;

        for (int i = 1; i < nums.length; i++) {
            if (nums[i] > nums[i - 1]) {
                currLen++;
                maxLen = Math.max(maxLen, currLen);
            } else {
                currLen = 1;
            }
        }

        return maxLen;
    }

    public static void main(String[] args) {
        int[] nums = {1, 3, 5, 4, 7};
        System.out.println(findLengthOfLCIS(nums));
    }
}
#include <iostream>
#include <vector>
using namespace std;

int findLengthOfLCIS(vector<int>& nums) {
    if (nums.empty()) return 0;
    int maxLen = 1, currLen = 1;

    for (size_t i = 1; i < nums.size(); ++i) {
        if (nums[i] > nums[i - 1]) {
            currLen++;
            maxLen = max(maxLen, currLen);
        } else {
            currLen = 1;
        }
    }
    return maxLen;
}

int main() {
    vector<int> nums = {1, 3, 5, 4, 7};
    cout << findLengthOfLCIS(nums) << endl;
    return 0;
}
function findLengthOfLCIS(nums) {
    if (nums.length === 0) return 0;
    let maxLen = 1, currLen = 1;

    for (let i = 1; i < nums.length; i++) {
        if (nums[i] > nums[i - 1]) {
            currLen++;
            maxLen = Math.max(maxLen, currLen);
        } else {
            currLen = 1;
        }
    }

    return maxLen;
}

const nums = [1, 3, 5, 4, 7];
console.log(findLengthOfLCIS(nums));
#include <stdio.h>

int findLengthOfLCIS(int* nums, int numsSize) {
    if (numsSize == 0) return 0;
    int maxLen = 1, currLen = 1;

    for (int i = 1; i < numsSize; i++) {
        if (nums[i] > nums[i - 1]) {
            currLen++;
            if (currLen > maxLen) {
                maxLen = currLen;
            }
        } else {
            currLen = 1;
        }
    }
    return maxLen;
}

int main() {
    int nums[] = {1, 3, 5, 4, 7};
    int length = sizeof(nums) / sizeof(nums[0]);
    printf("%d\n", findLengthOfLCIS(nums, length));
    return 0;
}
using System;

class LCIS {
    public static int FindLengthOfLCIS(int[] nums) {
        if (nums.Length == 0) return 0;
        int maxLen = 1, currLen = 1;

        for (int i = 1; i < nums.Length; i++) {
            if (nums[i] > nums[i - 1]) {
                currLen++;
                maxLen = Math.Max(maxLen, currLen);
            } else {
                currLen = 1;
            }
        }

        return maxLen;
    }

    static void Main() {
        int[] nums = {1, 3, 5, 4, 7};
        Console.WriteLine(FindLengthOfLCIS(nums));
    }
}

In the Python solution, we loop through the list of numbers, check if the sequence continues to be increasing, and update or reset the current sequence length accordingly.

Complexity

Time Complexity: O(n), where n is the number of elements in the list.
Space Complexity: O(1).

Try this approach in the editor

Approach 2: Greedy Approach

The greedy approach leverages a single pass through the array to determine the maximum length of an increasing subsequence. This method is optimal because it immediately processes each element only once, updating the sequence lengths on the fly, and computing the maximum without revisiting any part of the array.

def find_length_of_LCIS(nums):
    max_len = 0
    curr_len = 0

    for i in range(len(nums)):
        if i == 0 or nums[i] > nums[i - 1]:
            curr_len += 1
            max_len = max(max_len, curr_len)
        else:
            curr_len = 1

    return max_len

nums = [1, 3, 5, 4, 7]
print(find_length_of_LCIS(nums))
public class LCIS {
    public static int findLengthOfLCIS(int[] nums) {
        int maxLen = 0, currLen = 0;

        for (int i = 0; i < nums.length; i++) {
            if (i == 0 || nums[i] > nums[i - 1]) {
                currLen++;
                maxLen = Math.max(maxLen, currLen);
            } else {
                currLen = 1;
            }
        }

        return maxLen;
    }

    public static void main(String[] args) {
        int[] nums = {1, 3, 5, 4, 7};
        System.out.println(findLengthOfLCIS(nums));
    }
}
#include <iostream>
#include <vector>
using namespace std;

int findLengthOfLCIS(vector<int>& nums) {
    int maxLen = 0, currLen = 0;

    for (size_t i = 0; i < nums.size(); ++i) {
        if (i == 0 || nums[i] > nums[i - 1]) {
            currLen++;
            maxLen = max(maxLen, currLen);
        } else {
            currLen = 1;
        }
    }
    return maxLen;
}

int main() {
    vector<int> nums = {1, 3, 5, 4, 7};
    cout << findLengthOfLCIS(nums) << endl;
    return 0;
}
function findLengthOfLCIS(nums) {
    let maxLen = 0, currLen = 0;

    for (let i = 0; i < nums.length; i++) {
        if (i === 0 || nums[i] > nums[i - 1]) {
            currLen++;
            maxLen = Math.max(maxLen, currLen);
        } else {
            currLen = 1;
        }
    }

    return maxLen;
}

const nums = [1, 3, 5, 4, 7];
console.log(findLengthOfLCIS(nums));
#include <stdio.h>

int findLengthOfLCIS(int* nums, int numsSize) {
    if (numsSize == 0) return 0;
    int maxLen = 0, currLen = 0;

    for (int i = 0; i < numsSize; i++) {
        if (i == 0 || nums[i] > nums[i - 1]) {
            currLen++;
            if (currLen > maxLen) {
                maxLen = currLen;
            }
        } else {
            currLen = 1;
        }
    }
    return maxLen;
}

int main() {
    int nums[] = {1, 3, 5, 4, 7};
    int length = sizeof(nums) / sizeof(nums[0]);
    printf("%d\n", findLengthOfLCIS(nums, length));
    return 0;
}
using System;

class LCIS {
    public static int FindLengthOfLCIS(int[] nums) {
        int maxLen = 0, currLen = 0;

        for (int i = 0; i < nums.Length; i++) {
            if (i == 0 || nums[i] > nums[i - 1]) {
                currLen++;
                maxLen = Math.Max(maxLen, currLen);
            } else {
                currLen = 1;
            }
        }

        return maxLen;
    }

    static void Main() {
        int[] nums = {1, 3, 5, 4, 7};
        Console.WriteLine(FindLengthOfLCIS(nums));
    }
}

This Python code implements a greedy check to only keep adjusts on a basic condition, replicating rolling continuity steps that keep sync throughout iterations in a lazy kind of sequence.

Complexity

Time Complexity: O(n)
Space Complexity: O(1).

Try this approach in the editor

Approach 3: One-pass Scan

We can traverse the array nums, using a variable cnt to record the length of the current consecutive increasing sequence. Initially, cnt = 1.

Then, we start from index i = 1 and traverse the array nums to the right. Each time we traverse, if nums[i - 1] < nums[i], it means that the current element can be added to the consecutive increasing sequence, so we set cnt = cnt + 1, and then update the answer to ans = max(ans, cnt). Otherwise, it means that the current element cannot be added to the consecutive increasing sequence, so we set cnt = 1.

After the traversal ends, we return the answer ans.

The time complexity is O(n), where n is the length of the array nums. The space complexity is O(1).

function findLengthOfLCIS(nums: number[]): number {
    let [ans, cnt] = [1, 1];
    for (let i = 1; i < nums.length; ++i) {
        if (nums[i - 1] < nums[i]) {
            ans = Math.max(ans, ++cnt);
        } else {
            cnt = 1;
        }
    }
    return ans;
}
func findLengthOfLCIS(nums []int) int {
	ans, cnt := 1, 1
	for i, x := range nums[1:] {
		if nums[i] < x {
			cnt++
			ans = max(ans, cnt)
		} else {
			cnt = 1
		}
	}
	return ans
}
impl Solution {
    pub fn find_length_of_lcis(nums: Vec<i32>) -> i32 {
        let mut ans = 1;
        let mut cnt = 1;
        for i in 1..nums.len() {
            if nums[i - 1] < nums[i] {
                ans = ans.max(cnt + 1);
                cnt += 1;
            } else {
                cnt = 1;
            }
        }
        ans
    }
}
class Solution {
    /**
     * @param Integer[] $nums
     * @return Integer
     */
    function findLengthOfLCIS($nums) {
        $ans = 1;
        $cnt = 1;
        for ($i = 1; $i < count($nums); ++$i) {
            if ($nums[$i - 1] < $nums[$i]) {
                $ans = max($ans, ++$cnt);
            } else {
                $cnt = 1;
            }
        }
        return $ans;
    }
}
Try this approach in the editor

Approach 4: Two Pointers

We can also use two pointers i and j to find each consecutive increasing sequence, and find the length of the longest consecutive increasing sequence as the answer.

The time complexity is O(n), where n is the length of the array nums. The space complexity is O(1).

function findLengthOfLCIS(nums: number[]): number {
    let ans = 1;
    const n = nums.length;
    for (let i = 0; i < n; ) {
        let j = i + 1;
        while (j < n && nums[j - 1] < nums[j]) {
            ++j;
        }
        ans = Math.max(ans, j - i);
        i = j;
    }
    return ans;
}
func findLengthOfLCIS(nums []int) int {
	ans := 1
	n := len(nums)
	for i := 0; i < n; {
		j := i + 1
		for j < n && nums[j-1] < nums[j] {
			j++
		}
		ans = max(ans, j-i)
		i = j
	}
	return ans
}
impl Solution {
    pub fn find_length_of_lcis(nums: Vec<i32>) -> i32 {
        let mut ans = 1;
        let n = nums.len();
        let mut i = 0;
        while i < n {
            let mut j = i + 1;
            while j < n && nums[j - 1] < nums[j] {
                j += 1;
            }
            ans = ans.max(j - i);
            i = j;
        }
        ans as i32
    }
}
class Solution {
    /**
     * @param Integer[] $nums
     * @return Integer
     */
    function findLengthOfLCIS($nums) {
        $ans = 1;
        $n = count($nums);
        $i = 0;
        while ($i < $n) {
            $j = $i + 1;
            while ($j < $n && $nums[$j - 1] < $nums[$j]) {
                $j++;
            }
            $ans = max($ans, $j - $i);
            $i = $j;
        }
        return $ans;
    }
}
Try this approach in the editor

Complexity comparison

ApproachComplexity
Sliding Window Approach

Time Complexity: O(n), where n is the number of elements in the list.
Space Complexity: O(1).

Greedy Approach

Time Complexity: O(n)
Space Complexity: O(1).

One-pass Scan–
Two Pointers–

Complexity analysis

ApproachTimeSpaceWhen to Use
Sliding WindowO(n)O(1)Useful when thinking in terms of continuous segments or adapting to other window-based problems
Greedy Linear ScanO(n)O(1)Best general solution; minimal code and optimal performance for interviews

Frequently asked questions

Is Longest Continuous Increasing Subsequence easy or hard?

Longest Continuous Increasing Subsequence is categorized as an Easy problem on LeetCode with an acceptance rate above 50%. The challenge focuses on recognizing that only adjacent comparisons matter and implementing a linear scan efficiently.

Longest Continuous Increasing Subsequence Python/Java solution

In Python or Java, iterate through the array while comparing each element with the previous one. Maintain two variables: currentLength and maxLength. Increment the current length if the sequence increases, otherwise reset it. The same O(n) greedy logic applies across Python, Java, C++, and other languages.

How to solve Longest Continuous Increasing Subsequence in O(n)?

Traverse the array from index 1 while maintaining a counter for the current increasing streak. Increase the counter when nums[i] > nums[i-1]; otherwise reset it to 1. Track the maximum value of this counter during the scan. This single-pass greedy method runs in O(n) time.

What is the best approach for Longest Continuous Increasing Subsequence?

The greedy linear scan is the best approach. Iterate once through the array and track the length of the current increasing run. If nums[i] > nums[i-1], extend the run; otherwise reset it. This achieves O(n) time and O(1) space, which is optimal.

Is Longest Continuous Increasing Subsequence asked at Google/Amazon/Meta?

Longest Continuous Increasing Subsequence is a common easy-level array question used in screening rounds and coding practice sets. Variations of consecutive increasing subarray problems appear in interviews at companies like Amazon, Google, and other tech firms to test array traversal and pattern recognition.

What data structure is used in Longest Continuous Increasing Subsequence?

The problem primarily uses a simple array traversal. No additional data structures such as hash maps or stacks are required. A few integer variables track the current sequence length and the maximum length found.

What is the time complexity of Longest Continuous Increasing Subsequence?

The optimal solution runs in O(n) time because the array is scanned once while comparing adjacent elements. Space complexity is O(1) since only a few counters are stored regardless of input size.

Comments

Now write it yourselfClose this page and solve Longest Continuous Increasing Subsequence in the editor, without looking.
Practise Longest Continuous Increasing Subsequence