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:
- Count of ways to split given string into two non-empty palindromes
- Split the string into minimum parts such that each part is in the another string
- Partition the string in two parts such that both parts have at least k different characters
- Divide N into K unique parts such that gcd of those parts is maximum
- Count ways to partition a string such that both parts have equal distinct characters
- Program to print all palindromes in a given range
- Count maximum-length palindromes in a String
- Count special palindromes in a String
- Check if suffix and prefix of a string are palindromes
- Test Case Generation | Set 5 (Generating random Sorted Arrays and Palindromes)
- Count alphanumeric palindromes of length N
- Divide a string in N equal parts
- Split the binary string into substrings with equal number of 0s and 1s
- Split a given string into substrings of length K with equal sum of ASCII values
- Count ways to split a Binary String into three substrings having equal count of zeros
- Ways to split string such that each partition starts with distinct character
- Check if any square (with one colored cell) can be divided into two equal parts
- Partition 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
- Find the number of ways to divide number into four parts such that a = c and b = d
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.