Three Consecutive Odds

easy array

Problem

Return true if there are three consecutive odd numbers in arr; else false.

Inputarr = [1,2,34,3,4,5,7,23,12]
Outputtrue
5, 7, 23 are three consecutive odds.

def three_consecutive_odds(arr):
    run = 0
    for x in arr:
        run = run + 1 if x % 2 else 0
        if run == 3: return True
    return False
function threeConsecutiveOdds(arr) {
  let r = 0;
  for (const x of arr) { r = (x & 1) ? r + 1 : 0; if (r === 3) return true; }
  return false;
}
class Solution {
    public boolean threeConsecutiveOdds(int[] arr) {
        int r = 0;
        for (int x : arr) { r = (x & 1) == 1 ? r + 1 : 0; if (r == 3) return true; }
        return false;
    }
}
bool threeConsecutiveOdds(vector& arr) {
    int r = 0;
    for (int x : arr) { r = (x & 1) ? r + 1 : 0; if (r == 3) return true; }
    return false;
}
Time: O(n) Space: O(1)