LeetCode Entry
1550. Three Consecutive Odds
Has window of 3 odds?
1550. Three Consecutive Odds easy
blog post
substack
youtube

Join me on Telegram
https://t.me/leetcode_daily_unstoppable/656
Problem TLDR
Has window of 3 odds? #easy
Intuition
Such questions are helping to start with a new language.
Approach
Can you make it shorter?
Complexity
-
Time complexity: \(O(n)\)
-
Space complexity: \(O(1)\) for Rust, O(n) for Kotlin, can be O(1) with
asSequence.
Code
fun threeConsecutiveOdds(arr: IntArray) =
arr.asList().windowed(3).any { it.all { it % 2 > 0 }}
pub fn three_consecutive_odds(arr: Vec<i32>) -> bool {
arr[..].windows(3).any(|w| w.iter().all(|n| n % 2 > 0))
}