Given a string str, the task is to find the minimum number of characters to be replaced to make a given string palindrome. Replacing a character means replacing it with any single character at the same position. We are not allowed to remove or add any characters.
If there are multiple answers, print the lexicographically smallest string.
Input: str = "geeks" Output: 2 geeks can be converted to geeeg to make it palindrome by replacing minimum characters. Input: str = "ameba" Output: 1 We can get "abeba" or "amema" with only 1 change. Among those two, "abeba" is lexicographically smallest.
Approach: Run a loop from 0 up to (length)/2-1 and check if a character at ith index i.e. s[i]!=s[length-i-1] then we will replace the alphabetically larger character with the one which is alphabetically smaller among them and continue the same process until all the elements gets traversed.
Below is the implementation of the above approach:
Minimum characters to be replaced = 2 geeeg
- Minimum characters to be added at front to make string palindrome
- Minimum number of deletions to make a string palindrome
- Minimum number of Appends needed to make a string palindrome
- Number of Counterclockwise shifts to make a string palindrome
- Minimum length of the sub-string whose characters can be used to form a palindrome of length K
- Print the arranged positions of characters to make palindrome
- Make lexicographically smallest palindrome by substituting missing characters
- Minimum removal to make palindrome permutation
- Find the player who rearranges the characters to get a palindrome string first
- 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 cost to convert string into palindrome
- Minimum reduce operations to covert a given string into a palindrome
- Minimum steps to delete a string after repeated deletion of palindrome substrings
- Number of positions where a letter can be inserted such that a string becomes palindrome
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.