DDSA Solutions

1550. Three Consecutive Odds

Time: O(n)
Space: O(1)

Problem Overview

Three Consecutive Odds (Unknown) asks you to solve a structured algorithmic task. This is a common Array pattern in coding interviews. Linear scan counting consecutive odd numbers; reset on even.

A full step-by-step explanation is being added. See the study guide for pattern-based practice.

Approach

Linear scan counting consecutive odd numbers; reset on even.

Related patterns: Array

1550.cs
C#
// Approach: Linear scan counting consecutive odd numbers; reset on even.
// Time: O(n) Space: O(1)

public class Solution
{
    public bool ThreeConsecutiveOdds(int[] arr)
    {
        int cnt = 0;
        for (int i = 0; i < arr.Length; i++)
        {
            if (arr[i] % 2 > 0)
                cnt++;
            else
                cnt = 0;

            if (cnt == 3)
                return true;
        }

        return false;
    }
}
Was this solution helpful?

Related Problems