Detect an Odd Run of Length Three. Given arr, decide whether some contiguous group of three entries contains only odd integers. Return a Boolean result; the odd values need not differ by two.
### Problem
Given `arr`, decide whether some contiguous group of three entries contains only odd integers. Return a Boolean result; the odd values need not differ by two.
```cpp
class Solution {
public:
bool threeConsecutiveOdds(vector<int>& arr);
};
```
### Examples
**Example 1:**
```text
arr = [8,3,5,9,2]
Output: true
Explanation: Indices 1 through 3 contain 3, 5, and 9.
```
**Example 2:**
```text
arr = [7,2,5,4,9]
Output: false
Explanation: Every odd run has length one.
```
### Constraints
- `1 <= arr.length <= 1000`.
- Each entry lies between `1` and `1000`, inclusive.
### Clarifying Questions
“Consecutive” refers to adjacent array positions, not consecutive odd values. Fewer than three entries cannot satisfy the condition.
```hint Inspect the structure
How do even separators and arrays shorter than three affect a qualifying group?
```
### Reasoning checkpoints
- Track adjacency rather than the total number of odd entries.
- Explain how an even entry breaks a candidate run.
### Optional extensions
How would the same scan detect a requested run length `k`?
Overview: Detect an Odd Run of Length Three. Given arr, decide whether some contiguous group of three entries contains only odd integers. Return a Boolean result; the odd values need not differ by two.
Given arr, decide whether some contiguous group of three entries contains only odd integers. Return a Boolean result; the odd values need not differ by two.
class Solution {
public:
bool threeConsecutiveOdds(vector<int>& arr);
};
Examples
Example 1:
arr = [8,3,5,9,2]
Output: true
Explanation: Indices 1 through 3 contain 3, 5, and 9.
Example 2:
arr = [7,2,5,4,9]
Output: false
Explanation: Every odd run has length one.
Constraints
1 <= arr.length <= 1000
.
Each entry lies between
1
and
1000
, inclusive.
Clarifying Questions Guidance
“Consecutive” refers to adjacent array positions, not consecutive odd values. Fewer than three entries cannot satisfy the condition.
Reasoning checkpoints
Track adjacency rather than the total number of odd entries.
Explain how an even entry breaks a candidate run.
Optional extensions
How would the same scan detect a requested run length k?