Given a string, convert the string to palindrome without any modifications like adding a character, removing a character, replacing a character etc.
Input : "mdaam" Output : "madam" or "amdma" Input : "abb" Output : "bab" Input : "geeksforgeeks" Output : "No Palindrome"
1. Count occurrences of all characters.
2. Count odd occurrences. If this count is greater than 1 or is equal to 1 and length of the string is even then obviously palindrome cannot be formed from the given string.
3. Initialize two empty strings firstHalf and secondHalf.
4. Traverse the map. For every character with count as count, attach count/2 characters to end of firstHalf and beginning of secondHalf.
5. Finally return the result by appending firstHalf and secondHalf
- Check if characters of a given string can be rearranged to form a palindrome
- Check if the characters in a string form a Palindrome in O(1) extra space
- Minimum length of the sub-string whose characters can be used to form a palindrome of length K
- Rearrange a string in the form of integer sum followed by the minimized character
- Rearrange characters in a string such that no two adjacent are same
- Rearrange a string so that all same characters become d distance away
- Rearrange a string so that all same characters become atleast d distance away
- Minimum insertions to form a palindrome | DP-28
- Minimum insertions to form shortest palindrome
- Next word that does not contain a palindrome and has characters from first k
- Check if a string can be rearranged to form special palindrome
- Minimum insertions to form a palindrome with permutations allowed
- Find index i such that prefix of S1 and suffix of S2 till i form a palindrome when concatenated
- Maximum length palindrome that can be created with characters in range L and R
- Check if a doubly linked list of characters is palindrome or not
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.