Find the length of the longest strictly increasing contiguous subarray

Quick Overview

Return the length of the longest contiguous subarray whose values strictly increase from left to right. The problem tests linear array scanning, the strict comparison on equal neighbors, and keeping a contiguous run apart from a general increasing subsequence.

Find the length of the longest strictly increasing contiguous subarray

Company: Pinterest

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

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 ```python 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 ```text 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. ```text 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. ```text 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.

Overview: Return the length of the longest contiguous subarray whose values strictly increase from left to right. The problem tests linear array scanning, the strict comparison on equal neighbors, and keeping a contiguous run apart from a general increasing subsequence.

Pinterest logo
Pinterest
Nov 25, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

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.