Skip to content

Practice Three Consecutive Odds

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#1550
LeetCode Problem

Three Consecutive Odds

Problem Statement

Return true if arr contains three adjacent entries that are all odd; otherwise return false. The entries must be consecutive positions, but their numeric values need not be consecutive integers. Practice approach: Keep a running count of adjacent odd entries. Increment it for an odd value and reset it for an even value. Return true as soon as the count reaches three. This scans at most n elements in O(n) time and O(1) extra space. Arrays shorter than three cannot qualify; an even entry breaks the streak.

Source: Three Consecutive Odds on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
arr = [2,6,4,1]
Output
false

# Example 2

Input
arr = [1,2,34,3,4,5,7,23,12]
Output
true

Constraints

1 <= arr.length <= 1000
1 <= arr[i] <= 1000

Related LeetCode Problems

Practice more problems similar to Three Consecutive Odds.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.