Given a string s we need to tell minimum characters to be appended (insertion at end) to make a string palindrome.
Input : s = "abede" Output : 2 We can make string palindrome as "abedeba" by adding ba at the end of the string. Input : s = "aabb" Output : 2 We can make string palindrome as"aabbaa" by adding aa at the end of the string.
The solution can be achieved by removing characters from the beginning of the string one by one and checking if the string is palindrome or not.
For Example, consider the above string, s = “abede”.
We check if the string is palindrome or not.
The result is false, then we remove the character from the beginning of string and now string becomes “bede”.
We check if the string is palindrome or not. The result is again false, then we remove the character from the beginning of string and now string becomes “ede”.
We check if the string is palindrome or not. The result is true, so the output becomes 2 which is the number of characters removed from the string.
Related Article :
Dynamic Programming | Set 28 (Minimum insertions to form a palindrome)
This article is contributed by Shubham Chaudhary. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Minimum number of bracket reversals needed to make an expression balanced
- Minimum number of bracket reversals needed to make an expression balanced | Set - 2
- Minimum number of letters needed to make a total of n
- Minimum minutes needed to make the time palindromic
- Minimum number of deletions to make a string palindrome
- Minimum number of deletions to make a string palindrome | Set 2
- Minimum number of characters to be replaced to make a given string Palindrome
- Minimum number of steps needed to remove the substring K from given string
- Minimum characters to be added at front to make string palindrome
- Count minimum swap to make string palindrome
- Number of Counterclockwise shifts to make a string palindrome
- Minimum removal to make palindrome permutation
- Minimum changes required to make each path in a matrix palindrome
- Remove a character from a string to make it a palindrome
- Minimum amount of lamps needed to be installed
- Sentence Palindrome (Palindrome after removing spaces, dots, .. etc)
- Count all palindrome which is square of a palindrome
- Minimum changes required to make first string substring of second string
- Least number of manipulations needed to ensure two strings have identical characters
- Number of closing brackets needed to complete a regular bracket sequence