- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to check three consecutive odds are present or not in Python
Suppose we have an array called nums, we have to check whether there are three consecutive odd numbers in nums or not.
So, if the input is like nums = [18,15,2,19,3,11,17,25,20], then the output will be True as there are three consecutive odds [3,11,17].
To solve this, we will follow these steps −
length:= size of nums
if length is same as 1 or length is same as 2, then
return False
otherwise,
for i in range 0 to size of nums - 3, do
if nums[i], nums[i+1] and nums[i+2] all are odds, then
return True
return False
Example (Python)
Let us see the following implementation to get better understanding −
def solve(nums): length=len(nums) if length==1 or length ==2: return False else: for i in range(len(nums)-2): if nums[i] % 2 != 0 and nums[i+1] % 2 != 0 and nums[i+2] % 2 != 0: return True return False nums = [18,15,2,19,3,11,17,25,20] print(solve(nums))
Input
[18,15,2,19,3,11,17,25,20]
Output
True
- Related Articles
- Program to check all 1s are present one after another or not in Python
- Program to check whether one value is present in BST or not in Python
- Program to check whether we can split list into consecutive increasing sublists or not in Python
- Program to check whether parentheses are balanced or not in Python
- Program to check a string can be split into three palindromes or not in Python
- Program to check programmers convention arrangements are correct or not in Python
- Program to check whether two sentences are similar or not in Python
- Program to check whether elements frequencies are even or not in Python
- Program to check points are forming convex hull or not in Python
- Program to check points are forming concave polygon or not in Python
- Program to check given push pop sequences are proper or not in python
- Program to check linked list items are forming palindrome or not in Python
- Program to check whether two string arrays are equivalent or not in Python
- Program to check strings are rotation of each other or not in Python
- Program to check all listed delivery operations are valid or not in Python

Advertisements