Magicsheet logo

Three Consecutive Odds

Easy
12.5%
Updated 8/1/2025

Asked by 5 Companies

Topics

Three Consecutive Odds

What is this problem about?

Simple pattern recognition in arrays is a great way to warm up for more complex problems. "Three Consecutive Odds" asks you to determine if an integer array contains three consecutive odd numbers. If it does, return true; otherwise, return false.

Why is this asked in interviews?

This three consecutive odds interview question is an "easy" level problem used by companies like Meta, Amazon, and Google. It tests your basic loop proficiency and your ability to check multiple adjacent elements without going out of bounds. It evaluates whether you can write clean, concise, and bug-free code for a simple requirement.

Algorithmic pattern used

This problem follows the Array interview pattern.

  1. Iterate through the array from the first element up to the n-2 element.
  2. For each index i, check if arr[i], arr[i+1], and arr[i+2] are all odd (using the modulo operator: x % 2 != 0).
  3. If the condition is met for any i, return true immediately.
  4. If the loop finishes without finding such a sequence, return false.

Example explanation

Array: [2, 6, 4, 1, 3, 5, 7, 10]

  1. Index 0-2: [2, 6, 4] (All even)
  2. Index 3-5: [1, 3, 5] (All odd!) The function returns true. If the array was [1, 2, 3, 4, 5, 6, 7], no three odds are adjacent, so it returns false.

Common mistakes candidates make

In "Three Consecutive Odds coding problem," the most common mistake is an "index out of bounds" error. Candidates often try to check i+1 or i+2 without stopping the loop early enough. Another mistake is using a counter that doesn't reset properly when an even number is encountered, which would incorrectly return true for [1, 2, 3, 4, 5].

Interview preparation tip

Practice "sliding window" or "adjacent element" checks until they are natural. Always be mindful of your loop boundaries. Even for simple problems, strive for the most readable code possible, as clarity is highly valued in technical interviews.

Similar Questions