LeetCode Entry
3350. Adjacent Increasing Subarrays Detection II
Max k of adjucent increasing k-windows
3350. Adjacent Increasing Subarrays Detection II medium blog post substack youtube

Join me on Telegram
https://t.me/leetcode_daily_unstoppable/1143
Problem TLDR
Max k of adjucent increasing k-windows #medium #counting
Intuition
In a single iteration, count of increasing numbers. Drop on non-increasing. Compare with previous.
Approach
- can use
chunk_byandwindowsin Rust
Complexity
-
Time complexity: \(O(n)\)
-
Space complexity: \(O(1)\), or O(n)
Code
// 870ms
fun maxIncreasingSubarrays(n: List<Int>): Int {
var a = 0; var b = 0; var p = 0
return n.maxOf { n ->
if (n > p) ++a else { b = a; a = 1 }
p = n; max(a/2, min(a, b))
}
}
// 26ms
pub fn max_increasing_subarrays(n: Vec<i32>) -> i32 {
once(0).chain(n.chunk_by(|a,b| a < b).map(|c| c.len() as i32)).collect::<Vec<_>>()
.windows(2).map(|c| c[0].min(c[1]).max(c[1]/2)).max().unwrap()
}