Skip to content

Instantly share code, notes, and snippets.

@Ifihan
Created May 11, 2025 22:50
Show Gist options
  • Save Ifihan/a51b4cf9d704059f3dd45fa085f5b7eb to your computer and use it in GitHub Desktop.
Save Ifihan/a51b4cf9d704059f3dd45fa085f5b7eb to your computer and use it in GitHub Desktop.
Three Consecutive Odds

Question

Approach

I iterate through the array while maintaining a counter that tracks consecutive odd numbers. Each time I encounter an odd number, I increment the counter. If the counter reaches 3, I immediately return True. If I encounter an even number, I reset the counter to 0.

Implementation

class Solution:
    def threeConsecutiveOdds(self, arr: List[int]) -> bool:
        count = 0
        for num in arr:
            if num % 2 == 1:
                count += 1
                if count == 3:
                    return True
            else:
                count = 0
        return False

Complexities

  • Time: O(n)
  • Space: O(1)
image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment