Three Consecutive Odds

Given an integer array arr, return true if it contains three odd numbers in a row (at three consecutive positions). Otherwise return false.

30:00

Three Consecutive Odds
easy
Free written solution
Topics
Companies

Given an integer array arr, return true if it contains three odd numbers in a row (at three consecutive positions). Otherwise return false.

Example 1:
Input: {"arr":[2,6,4,1]}
Output: false
Constraints:
  • 1≤arr.length≤10001 \leq \text{arr.length} \leq 1000

  • 1≤arr[i]≤10001 \leq \text{arr}[i] \leq 1000

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"arr":[2,6,4,1]}

Keep one counter: the length of the run of odd numbers ending at the current position. Three in a row means the counter reaches 3.

arr: odd numbers marked with a dot, current run bracketed

i

2

i

6

i

4

i

1

streak meter (needs 3)

1
2
3

streak = 0

Variables
VariableValue
streak0
DepthFunction Call
Stack empty
0/9