1550. Three Consecutive Odds
UnknownView on LeetCode
Time: O(n)
Space: O(1)
Problem Overview
Three Consecutive Odds (Unknown) asks you to solve a structured algorithmic task. This is a common Array pattern in coding interviews. Linear scan counting consecutive odd numbers; reset on even.
A full step-by-step explanation is being added. See the study guide for pattern-based practice.
Approach
Linear scan counting consecutive odd numbers; reset on even.
Related patterns: Array
1550.cs
C#
// Approach: Linear scan counting consecutive odd numbers; reset on even.
// Time: O(n) Space: O(1)
public class Solution
{
public bool ThreeConsecutiveOdds(int[] arr)
{
int cnt = 0;
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] % 2 > 0)
cnt++;
else
cnt = 0;
if (cnt == 3)
return true;
}
return false;
}
}Was this solution helpful?
Related Problems
- 4. Median of Two Sorted Arrays(Hard)
- 11. Container With Most Water(Medium)
- 15. 3Sum(Medium)
- 16. 3Sum Closest(Medium)
- 26. Remove Duplicates from Sorted Array(Easy)
- 27. Remove Element(Easy)