Longest Continuous Increasing Subsequence

Given an unsorted array of integers nums, return the length of the longest continuous increasing subsequence (subarray). The subsequence must be strictly increasing. A continuous increasing subsequence is defined by two indices 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].

30:00

Longest Continuous Increasing Subsequence
easy
Free written solution
Topics
Companies

Given an unsorted array of integers nums, return the length of the longest continuous increasing subsequence (subarray). The subsequence must be strictly increasing. A continuous increasing subsequence is defined by two indices 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
Constraints:
  • 1≤nums.length≤1041 \leq \text{nums.length} \leq 10^4

  • −109≤nums[i]≤109-10^9 \leq \text{nums}[i] \leq 10^9

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"nums":[1,3,5,4,7]}

A single element is already an increasing run of length 1, so best = 1. The run starts at index 0.

nums: blue = current run, green frame = best run

1

3

5

4

7

0

i

1

 

2

 

3

 

4

 

current run (start = 0)

1

best [0..0]

1

Variables
VariableValue
i0
start0
run1
best1
DepthFunction Call
Stack empty
0/7