Off-by-one on range boundaries
Wrong move: Loop endpoints miss first/last candidate.
Usually fails on: Fails on minimal arrays and exact-boundary answers.
Fix: Re-derive loops from inclusive/exclusive ranges before coding.
Build confidence with an intuition-first walkthrough focused on array fundamentals.
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] <= 109Problem summary: 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].
Start with the most direct exhaustive search. That gives a correctness anchor before optimizing.
Pattern signal: Array
[1,3,5,4,7]
[2,2,2,2,2]
number-of-longest-increasing-subsequence)minimum-window-subsequence)consecutive-characters)longest-increasing-subsequence-ii)Source-backed implementations are provided below for direct study and interview prep.
// Accepted solution for LeetCode #674: Longest Continuous Increasing Subsequence
class Solution {
public int findLengthOfLCIS(int[] nums) {
int ans = 1;
for (int i = 1, cnt = 1; i < nums.length; ++i) {
if (nums[i - 1] < nums[i]) {
ans = Math.max(ans, ++cnt);
} else {
cnt = 1;
}
}
return ans;
}
}
// Accepted solution for LeetCode #674: Longest Continuous Increasing Subsequence
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
}
# Accepted solution for LeetCode #674: Longest Continuous Increasing Subsequence
class Solution:
def findLengthOfLCIS(self, nums: List[int]) -> int:
ans = cnt = 1
for i, x in enumerate(nums[1:]):
if nums[i] < x:
cnt += 1
ans = max(ans, cnt)
else:
cnt = 1
return ans
// Accepted solution for LeetCode #674: Longest Continuous Increasing Subsequence
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
}
}
// Accepted solution for LeetCode #674: Longest Continuous Increasing Subsequence
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;
}
Use this to step through a reusable interview workflow for this problem.
Two nested loops check every pair or subarray. The outer loop fixes a starting point, the inner loop extends or searches. For n elements this gives up to n²/2 operations. No extra space, but the quadratic time is prohibitive for large inputs.
Most array problems have an O(n²) brute force (nested loops) and an O(n) optimal (single pass with clever state tracking). The key is identifying what information to maintain as you scan: a running max, a prefix sum, a hash map of seen values, or two pointers.
Review these before coding to avoid predictable interview regressions.
Wrong move: Loop endpoints miss first/last candidate.
Usually fails on: Fails on minimal arrays and exact-boundary answers.
Fix: Re-derive loops from inclusive/exclusive ranges before coding.