09 Sept 2026Go / Python / TypeScriptEasy

Longest Continuous Increasing Subsequence

Find the length of the longest strictly increasing contiguous segment.

Track the current increasing run and reset it whenever the next value is not greater than its predecessor.

complexity

O(n) time and O(1) extra space.

solution files

  • Go longest-continuous-increasing-subsequence/solution.go
  • Python longest-continuous-increasing-subsequence/solution.py
  • TypeScript longest-continuous-increasing-subsequence/solution.ts

Solution files

Golongest-continuous-increasing-subsequence/solution.go
package main

func findLengthOfLCIS(nums []int) int {
	best, run := 0, 0
	for index, value := range nums {
		if index == 0 || value > nums[index-1] {
			run++
		} else {
			run = 1
		}
		if run > best {
			best = run
		}
	}
	return best
}
Pythonlongest-continuous-increasing-subsequence/solution.py
class Solution:
    def findLengthOfLCIS(self, nums: list[int]) -> int:
        best = run = class="syntax-number">0
        for index, value in enumerate(nums):
            run = run + class="syntax-number">1 if index == class="syntax-number">0 or value > nums[index - class="syntax-number">1] else class="syntax-number">1
            best = max(best, run)
        return best
TypeScriptlongest-continuous-increasing-subsequence/solution.ts
function findLengthOfLCIS(nums: number[]): number {
  let best = class="syntax-number">0;
  let run = class="syntax-number">0;
  for (let index = class="syntax-number">0; index < nums.length; index += class="syntax-number">1) {
    run = index === class="syntax-number">0 || nums[index] > nums[index - class="syntax-number">1] ? run + class="syntax-number">1 : class="syntax-number">1;
    best = Math.max(best, run);
  }
  return best;
}