LeetCode Entry
3349. Adjacent Increasing Subarrays Detection I
Any increasing consequent windows size k
3349. Adjacent Increasing Subarrays Detection I medium blog post substack youtube

Join me on Telegram
https://t.me/leetcode_daily_unstoppable/1142
Problem TLDR
Any increasing consequent windows size k #easy
Intuition
Just brute-force every index. O(1) memory solution: count increasings, keep previous and current, check
Approach
- corner case: single 2k increasing chunk
Complexity
-
Time complexity: \(O(n)\)
-
Space complexity: \(O(n)\), can be O(1)
Code
// 379ms
fun hasIncreasingSubarrays(n: List<Int>, k: Int) = n.indices
.any { i -> fun List<Int>.g()=this==sorted()&&toSet().size==k;
n.slice(i..<min(n.size,i+k)).g() &&
n.slice(min(n.size-1,i+k)..<min(n.size,i+k+k)).g()
}
// 5ms
pub fn has_increasing_subarrays(n: Vec<i32>, k: i32) -> bool {
once(0).chain(n.chunk_by(|a,b| a < b).map(|c|c.len() as i32))
.collect::<Vec<_>>().windows(2).any(|c| c[0].min(c[1]).max(c[1]/2) >= k)
}