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:
- Partition the string in two parts such that both parts have at least k different characters
- Divide a string in N equal parts
- Divide N into K unique parts such that gcd of those parts is maximum
- Check if any square (with one colored cell) can be divided into two equal parts
- Split the binary string into substrings with equal number of 0s and 1s
- Divide a number into two parts
- Partition a number into two divisible parts
- Possible cuts of a number such that maximum parts are divisible by 3
- Partition N into M parts such that difference between Max and Min part is smallest
- Find the number of ways to divide number into four parts such that a = c and b = d
- Count special palindromes in a String
- Check if suffix and prefix of a string are palindromes
- Count maximum-length palindromes in a String
- Split N^2 numbers into N groups of equal sum
- How to split a string in C/C++, Python and Java?
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.