Skip to main content
Back to problems
#3349
Easy Algorithms

Adjacent increasing subarrays detection i

Array
48.0% acceptance
Feb 24, 2026
481
59
Given an array nums of n integers and an integer k, determine whether there exist two adjacent subarrays of length k such that both subarrays are strictly increasing. Specifically, check if there are two subarrays starting at indices a and b (a < b), where: Both subarrays nums[a..a + k - 1] and nums[b..b + k - 1] are strictly increasing. The subarrays must be adjacent, meaning b = a + k. Return true if it is possible to find two such subarrays, and false otherwise.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn has_increasing_subarrays(nums: Vec<i32>, k: i32) -> bool {
    let k = k as usize;
    let n = nums.len();
    let is_inc = |start: usize| -> bool {
      (0..k-1).all(|i| nums[start + i] < nums[start + i + 1])
    };
    for a in 0..=(n - 2 * k) {
      if is_inc(a) && is_inc(a + k) { return true; }
    }
    false
  }
}