
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check if all the palindromic sub-strings are of odd lengths in Python
Suppose we have a string s we have to check whether its palindromic sub-strings are of odd length or not.
So, if the input is like s = "levelopmadam", then the output will be True as there are two palindromic substrings "level" and "madam" both are of odd length.
To solve this, we will follow these steps −
- for i in range 0 to size of s, do
- temp := blank string
- for j in range i to size of s, do
- temp := temp concatenate s[j]
- if size of temp is even and temp is palindrome, then
- return False
- return True
Let us see the following implementation to get better understanding −
Example
def is_palindrome(s): return s == s[::-1] def solve(s): for i in range(len(s)): temp = "" for j in range(i, len(s)): temp += s[j] if len(temp) % 2 == 0 and is_palindrome(temp): return False return True s = "levelopmadam" print(solve(s))
Input
"levelopmadam"
Output
True
- Related Questions & Answers
- Find all distinct palindromic sub-strings of a given String in Python
- Find all palindromic sub-strings of a given string - Set 2 in Python
- Program to check whether all palindromic substrings are of odd length or not in Python
- Check if a string contains a palindromic sub-string of even length in Python
- Check if a string contains a palindromic sub-string of even length in C++
- Count pairs of non-overlapping palindromic sub-strings of the given string in C++
- Check if all sub-numbers have distinct Digit product in Python
- Python - Check if two strings are isomorphic in nature
- Check if strings are rotations of each other or not in Python
- Check if all bits of a number are set in Python
- Check if all elements of the array are palindrome or nots in Python
- Check if all elements of the array are palindrome or not in Python
- Check if all array elements are distinct in Python
- Python - Check if frequencies of all characters of a string are different
- Count of sub-strings that do not contain all the in C++
Advertisements