Back to problems Sign in to unlock
Leetcode
Easy
Arrays
Math
Three Consecutive Odds
Determine whether an integer array contains three odd numbers in a row.
Acceptance 100%
Also Available On
Other platform versions and source mappings for the same problem.
LeetCode 1550
gfgProblem Statement
Problem
Given an integer array arr, determine whether there exists a contiguous subarray of length 3 where all three elements are odd.
Return true if such a subarray exists; otherwise return false.
The array may contain positive, negative, or zero values.
Input Format
- An integer array
arr.
Output Format
- Return
trueif there are three consecutive odd numbers anywhere in the array. - Otherwise, return
false.
Constraints
1 <= arr.length- Elements are integers.
- Oddness is determined by whether an integer is not divisible by 2.
Examples
Sample cases returned by the problem API.
Example 1
Input
arr = [2,6,4,1]
Output
false
Explanation
There are not three odd numbers next to each other.
Example 2
Input
arr = [1,2,34,3,4,5,7,23,12]
Output
true
Explanation
The subarray [5, 7, 23] contains three consecutive odd numbers.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.
Guided hints
Editorial and discussion links
Concept map and variants
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.