S is string containing only lowercase English alphabets. We need to find if there exists at least one palindromic sub-string whose length is even.
Input : aassss Output : YES Input : gfg Output : NO
Notice that a palindrome of even length must contain two same alphabets in the middle. So we just need to check for this condition. If we find two consecutive same alphabets in the string then we output “YES” otherwise “NO”.
Below is the implementation:
# Python 3 program to check if there is
# a substring palindrome of even length.
# function to check if two consecutive
# same characters are present
for i in range (0, len(s)):
if (s[i] == s[i + 1]):
# Driver Code
s = “xzyyz”
# This code is contributed
# by iAyushRAJ
- Maximum length palindromic substring such that it starts and ends with given char
- Check if all the palindromic sub-strings are of odd length
- Number of strings of length N with no palindromic sub string
- Find length of longest subsequence of one string which is substring of another string
- Longest Palindromic Substring using Palindromic Tree | Set 3
- Convert to a string that is repetition of a substring of k length
- Maximum length substring with highest frequency in a string
- Minimum cuts required to convert a palindromic string to a different palindromic string
- Queries to check if string B exists as substring in string A
- Check if a string is substring of another
- Length of the largest substring which have character with frequency greater than or equal to half of the substring
- Python | Check if a Substring is Present in a Given String
- Check if string can be made lexicographically smaller by reversing any substring
- Make palindromic string non-palindromic by rearranging its letters
- Longest Non-palindromic substring
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.