Given a string ‘s’, the task is to check whether the string has both prefix and suffix substrings of length greater than 1 which are palindromes.
Print ‘YES’ if the above condition is satisfied or ‘NO’ otherwise.
Input : s = abartbb Output : YES Explanation : The string has prefix substring 'aba' and suffix substring 'bb' which are both palindromes, so the output is 'YES'. Input : s = abcc Output : NO Explanation : The string has no prefix substring which is palindrome, it only has a suffix substring 'cc' which is a palindrome. So the output is 'NO'.
- First, check all the prefix substrings of length > 1 to find if there’s any which is a palindrome.
- Check all the suffix substrings as well.
- If both the conditions are true, then the output is ‘YES’.
- Otherwise, the output is ‘NO’.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find the longest sub-string which is prefix, suffix and also present inside the string | Set 2
- Find the longest sub-string which is prefix, suffix and also present inside the string
- Longest palindromic string formed by concatenation of prefix and suffix of a string
- String from prefix and suffix of given two strings
- Print the longest prefix of the given string which is also the suffix of the same string
- Longest Palindrome in a String formed by concatenating its prefix and suffix
- Check if a string is suffix of another
- Longest prefix which is also suffix
- Find index i such that prefix of S1 and suffix of S2 till i form a palindrome when concatenated
- Count special palindromes in a String
- Count maximum-length palindromes in a String
- Count of ways to split given string into two non-empty palindromes
- Longest string in an array which matches with prefix of the given string
- Minimize length of prefix of string S containing all characters of another string T
- Longest string which is prefix string of at least two strings
- Split a string in equal parts such that all parts are palindromes
- Count of distinct substrings of a string using Suffix Array
- Count of distinct substrings of a string using Suffix Trie
- Sub-strings of a string that are prefix of the same string
- Strings from an array which are not prefix of any other string
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.