Given an unsorted array of integers nums, return the length of the longest continuous increasing subsequence (that is, a 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 nums[i] < nums[i + 1] for each l <= i < r.
Function Signature
def longest_increasing_run_length(nums: list[int]) -> int:
Rules
-
Equal neighbors end a run, because each value must be strictly greater than the one before it.
-
A single element is a run of length 1, so the answer is always at least 1.
Constraints
-
1 <= len(nums) <= 10^4
-
-10^9 <= nums[i] <= 10^9
Examples
Input: nums = [1, 3, 5, 4, 7]
Output: 3
The longest continuous increasing subsequence is [1, 3, 5] with length 3. Although [4, 7] is also increasing, it has length 2.
Input: nums = [2, 2, 2, 2, 2]
Output: 1
No two consecutive elements are strictly increasing, so the longest continuous increasing subsequence has length 1.
Input: nums = [10, -2, 0, 0, 3, 8, 9]
Output: 4
The runs are [10], [-2, 0] and [0, 3, 8, 9]. The repeated 0 starts a new run, and the longest run ends at the last index.