EasyArraysSliding Window

Longest Continuous Increasing Subsequence

LeetCode
1 approach, code in all languages

Given an integer array, find the length of the longest run of elements that is strictly increasing and unbroken, meaning the chosen elements must sit next to each other in the original order. Ties in value break the streak, so equal neighbours cannot be part of the same run.

You can think of it as a window that keeps growing while each new element is larger than the one before it, and collapses back to size one the instant that rule is violated.

Example 1

Input: nums = [1,3,5,4,7]

Output: 3

The run 1,3,5 climbs for three elements before 4 breaks the streak; 4,7 only reaches length two.

Example 2

Input: nums = [2,2,2,2]

Output: 1

No neighbour is strictly larger than the previous one, so the longest strictly increasing run is a single element.

Constraints

  • 1 ≤ nums.length ≤ 10^4
  • -10^9 ≤ nums[i] ≤ 10^9
You've got the patterns

Patterns get you through the screen. Shipping gets you hired.

FDE Coach is a cohort-based program in frontend, backend, AWS, and AI where you build real products and get referred to 200+ hiring partners. The free live workshop is the fastest way to see how we teach.

750+ engineers trained · frontend, backend, AWS & AI

August 15 · 0d left
Enroll Now