Given a string str, the task is to split the string into minimum parts such that each part is of same length and each part is a palindrome. Print the required number of parts.
Input: str = “civicbob”
“b”, “b”, “c”, “c”, “i”, “i”, “v” and “o” are the required partitions. “civic” and “bob” are also palindromes but they are not of equal length
Input: str = “noonpeep”
- Count the number of odd appearing characters and store it in countOdd.
- Sum the frequencies of all the even occurring characters and store it in sumEven.
- Since, no more than one odd frequency character can be a part of the same palindrome. So, if (sumEven / 2) % countOdd = 0 then the answer is countOdd as sumEven can be divided into countOdd parts.
- Else, we can still divide the odd occurring characters into the palindrome pairs. For example, if the character a appears 3 times i.e. aaa then aa can be a part of some palindrome while leaving a as odd (without affecting the original frequency).
Below is the implementation of the above approach:
- Divide a string in N equal parts
- Check if any square (with one colored cell) can be divided into two equal parts
- Partition a number into two divisble parts
- Partiton N into M parts such that difference between Max and Min part is smallest
- Possible cuts of a number such that maximum parts are divisible by 3
- Count special palindromes in a String
- Count maximum-length palindromes in a String
- Check if suffix and prefix of a string are palindromes
- Split N^2 numbers into N groups of equal sum
- Split the string into substrings using delimiter
- How to split a string in C/C++, Python and Java?
- Check if given string can be split into four distinct strings
- Split numeric, alphabetic and special symbols from a String
- Ways to split string such that each partition starts with distinct character
- Longest sub-string having frequency of each character less than equal to k
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.
Improved By : Ryuga