Three Consecutive Odds - Problem

Given an integer array arr, return true if there are three consecutive odd numbers in the array. Otherwise, return false.

An odd number is any integer that is not divisible by 2.

Input & Output

Example 1 — Basic Case
$ Input: arr = [2,1,3,5,8]
Output: true
💡 Note: The elements at indices 1, 2, and 3 are [1,3,5] which are three consecutive odd numbers
Example 2 — No Three Consecutive
$ Input: arr = [1,2,3,4,5]
Output: false
💡 Note: No three consecutive elements are all odd. We have [1,2,3] but 2 is even
Example 3 — All Odds
$ Input: arr = [1,3,5,7,9]
Output: true
💡 Note: The first three elements [1,3,5] are all odd and consecutive

Constraints

  • 1 ≤ arr.length ≤ 1000
  • -1000 ≤ arr[i] ≤ 1000

Visualization

Tap to expand
Three Consecutive Odds Problem OverviewInput Array:21358evenoddoddoddevenThree consecutive odds found!Found: [1, 3, 5] at indices 1, 2, 3Output: true
Understanding the Visualization
1
Input Array
Array with mixed odd and even numbers
2
Process
Find three consecutive odd numbers
3
Output
Return true if found, false otherwise
Key Takeaway
🎯 Key Insight: Use a counter to track consecutive odds, resetting when encountering an even number
Asked in
Amazon 25 Apple 15
23.5K Views
Medium Frequency
~10 min Avg. Time
842 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen