Given a string str, the task is to check if it is possible to split the given string into even length palindromic substrings.
Input: str = “abbacc”
Strings “abba” and “cc” are the even length palindromic substrings.
Input: str = “abcde”
No even length palindromic substrings possible.
Approach: The idea is to use Stack Data Structure. Below are the steps:
- Initialise a empty stack.
- Traverse the given string str.
- For each characters in the given string, do the following:
- If the charactor is equal to the charactor at the top of the stack then pop the top element from the stack.
- Else push the current charactor into the stack.
- If stack is empty after the above steps then the given string can be break into palindromic substring of even length.
- Else the given string cannot be break into palindromic substring of even length.
Below is the implementation of the above approach:
Time Complexity: O(N), where N is the length of the given string.
- Check if a string can be split into substrings starting with N followed by N characters
- Split a given string into substrings of length K with equal sum of ASCII values
- Check if a Palindromic String can be formed by concatenating Substrings of two given Strings
- Check if a string contains a palindromic sub-string of even length
- Split the string into substrings using delimiter
- Split the binary string into substrings with equal number of 0s and 1s
- Remove minimum characters from string to split it into three substrings under given constraints
- Count ways to split a Binary String into three substrings having equal count of zeros
- Check if given string can be split into four distinct strings
- Check if a string can be split into two strings with same number of K-frequent characters
- Length of longest Palindromic Subsequence of even length with no two adjacent characters same
- Minimum cuts required to convert a palindromic string to a different palindromic string
- Count all Prime Length Palindromic Substrings
- Minimum number of substrings the given string can be splitted into that satisfy the given conditions
- Minimum flips required to convert given string into concatenation of equal substrings of length K
- Make palindromic string non-palindromic by rearranging its letters
- Generate a String of having N*N distinct non-palindromic Substrings
- Permutation of given string that maximizes count of Palindromic substrings
- Rearrange the string to maximize the number of palindromic substrings
- Lexicographically all Shortest Palindromic Substrings from a given 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.