Three Odds in a Row
Imagine scanning a list of numbers and looking for a short streak of three odd values in a row. Write a function three_consecutive_odds that checks whether such a streak exists in arr. The three odd numbers must be next to each other, with no other elements between them. Return True if the streak exists, otherwise return False.
Примеры
Ввод
[2, 6, 4, 1]Вывод
FalseВвод
[1, 2, 34, 3, 4, 5, 7, 23, 12]Вывод
TrueВвод
[1, 3, 5]Вывод
TrueНужно реализовать
def three_consecutive_odds(arr: list[int]) -> bool:
Теги
array
Melde dich an, um den Einreichungsverlauf zu sehen
AnmeldenMelde dich an, um den KI-Mentor zu nutzen
AnmeldenVisible tests
1
Input
[2,6,4,1]Expected
False2
Input
[1,2,34,3,4,5,7,23,12]Expected
True3
Input
[1,3,5]Expected
True4
Input
[1,1,2,1,1,1]Expected
True5
Input
[]Expected
False6
Input
[7,7]Expected
FalseFocus radio
Paused · SomaFM · Fluid