""" 1550.1 - Solution 1 - Consecutive Counter """
#####################################################################################
# Imports
#####################################################################################
from typing import List
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def threeConsecutiveOdds(self, arr: List[int]) -> bool:
"""Three Consecutive Odds Function"""
count = 0
for num in arr:
if num % 2 == 1:
count += 1
if count == 3:
return True
else:
count = 0
return False
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().threeConsecutiveOdds([2, 6, 4, 1])) # False
print(Solution().threeConsecutiveOdds([1, 2, 34, 3, 4, 5, 7, 23, 12])) # True
print(Solution().threeConsecutiveOdds([1, 3, 5])) # True
print(Solution().threeConsecutiveOdds([1, 1, 2, 1, 1])) # False
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()
""" 1550.2 - Solution 2 - Bitwise Check """
#####################################################################################
# Imports
#####################################################################################
from typing import List
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def threeConsecutiveOdds(self, arr: List[int]) -> bool:
"""Three Consecutive Odds Function"""
count = 0
for num in arr:
count = count + 1 if num & 1 else 0
if count == 3:
return True
return False
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().threeConsecutiveOdds([2, 6, 4, 1])) # False
print(Solution().threeConsecutiveOdds([1, 2, 34, 3, 4, 5, 7, 23, 12])) # True
print(Solution().threeConsecutiveOdds([1, 3, 5])) # True
print(Solution().threeConsecutiveOdds([1, 1, 2, 1, 1])) # False
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()