Skip to content
EasyArraysAI interview only

Three Consecutive Odds

Asked atamazongoogleadobe

01 · Problem

Given an integer array arr, return true if there is some position where three odd numbers appear back to back (at indices i, i + 1 and i + 2). Otherwise return false.

The odd values must be adjacent in the array; odd numbers separated by an even number do not count. An array with fewer than three elements always returns false.

02 · Examples

Example 01
Input
arr = [4,1,3,5,8]
Output
true

The values 1, 3 and 5 sit at indices 1, 2 and 3 and are all odd.

Example 02
Input
arr = [2,7,9,4,11,13]
Output
false

The longest run of adjacent odd values has length 2 (7, 9 and 11, 13).

Example 03
Input
arr = [1,1]
Output
false

There are fewer than three elements, so no run of three can exist.

03 · Constraints

  • 011 <= arr.length <= 1000
  • 021 <= arr[i] <= 1000
  • 03arr may contain duplicate values

04 · Optimal complexity

Time
O(n)
Space
O(1)
05 · Two ways to work on it

Practice it alone or rehearse it as an interview.

Practice Mode gives you an editor and test runs, nothing else. AI Interview Mode puts a voice interviewer on the other side, adds a clock, and ends with a scored summary of the round.