Skip to main content
Back to problems
#2393
Medium Algorithms

Count strictly increasing subarrays

Array Math Dynamic Programming
71.4% acceptance
Mar 31, 2026
143
2
You are given an array nums consisting of positive integers. Return the number of subarrays of nums that are in strictly increasing order. A subarray is a contiguous part of an array.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn count_subarrays(nums: Vec<i32>) -> i64 {
    let mut count = 0i64;
    let mut len = 1i64;
    count += 1;
    for i in 1..nums.len() {
      if nums[i] > nums[i - 1] {
        len += 1;
      } else {
        len = 1;
      }
      count += len;
    }
    count
  }
}