LeetCode Entry

1550. Three Consecutive Odds

1.07.2024 easy 2024 kotlin rust

Has window of 3 odds?

1550. Three Consecutive Odds easy blog post substack youtube 2024-07-01_07-12_1.webp

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))
    }