File: longest-continuous-increasing-subsequence/solution.py

Date: 2026-06-06

Time: 17:26

Purpose

This file implements LeetCode #674 — Longest Continuous Increasing Subsequence. It solves the problem of finding the length of the longest strictly increasing contiguous subarray within a list of integers. It's one of hundreds of solution files in the leetcode-implementations repo, each following an identical structure: a Solution class with a single method matching the LeetCode interface.

Key Components

Solution.findLengthOfLCIS(self, nums: List[int]) -> int — The only method. Takes a list of integers and returns the length of the longest contiguous run where each element is strictly greater than the previous one.

Patterns

Single-pass greedy scan — This is the classic "extend or reset" pattern for contiguous subarray problems. You maintain a running counter for the current window, extend it when the condition holds, and reset it when it doesn't. The global max is updated inline during extension rather than at the end, which avoids a separate post-loop check.

The comparison if curlen > maxlen is done inside the if branch rather than unconditionally after the else. This is a micro-optimization: maxlen only needs updating when curlen grows, never when it resets to 1.

Dependencies

Imports: typing.List — used only for the type annotation on nums.

Imported by: longest-continuous-increasing-subsequence/test_solution.py directly. The massive "Imported By" list in the prompt is an artifact of how the repo's test harness resolves imports — those other test files don't actually depend on this solution.

Flow

1. Initialize both maxlen and curlen to 1 (any non-empty array has at least a length-1 increasing run).

2. Iterate from index 1 through len(nums) - 1.

3. At each index, compare nums[i] to nums[i-1]:

4. Return max_len.

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

Invariants

Error Handling

None. No input validation, no exception handling. The method trusts the caller to provide a non-empty list of integers, matching LeetCode's guaranteed constraints.

Topics to Explore

Beliefs