Given a string str, the task is to count the number of ways a palindromic sub-string could be formed by concatenation of three sub-strings x, y and z of the string str such that all of them are non-overlapping i.e. sub-string y occurs after sub-string x and sub-string z occurs after sub-string y.
Input: str = “abca”
The two valid pairs are (“a”, “b”, “a”) and (“a”, “c”, “a”)
Input: str = “abba”
Approach: Find all the possible pairs of three non-overlapping sub-strings and for every pairs check whether the string generated by their concatenation is a palindrome or not. If yes then increment the count.
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.
- Subarray of length K whose concatenation forms a palindrome
- Count pair of strings whose concatenation of substrings form a palindrome
- Count of pairs of strings whose concatenation forms a palindromic string
- Count all palindrome which is square of a palindrome
- Count ways to split a Binary String into three substrings having equal count of zeros
- Lexicographical concatenation of all substrings of a string
- Minimum flips required to convert given string into concatenation of equal substrings of length K
- Minimize cost to convert given string into concatenation of equal substrings of length K
- Check if a linked list of strings forms a palindrome
- Check if longest connected component forms a palindrome in undirected graph
- Count substrings of a given string whose anagram is a palindrome
- Remove minimum characters from string to split it into three substrings under given constraints
- Split string into three palindromic substrings with earliest possible cuts
- Minimum steps to delete a string after repeated deletion of palindrome substrings
- Count of substrings which contains a given character K times
- Sentence Palindrome (Palindrome after removing spaces, dots, .. etc)
- Count pair of strings whose concatenation has every vowel
- Find the starting indices of the substrings in string (S) which is made by concatenating all words from a list(L)
- Ropes Data Structure (Fast String Concatenation)
- Longest palindromic string formed by concatenation of prefix and suffix of a 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 email@example.com. 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.