Input: S = “pqrstsuvwrqp”
Removal of the substring “uvw” modifies S to a palindromic string.
Input: S = “geeksforskeeg”
Removal of substring “or” modifies S to a palindromic string.
Approach: The idea is to include maximum size prefix and suffix from the given string S whose concatenation forms a palindrome. Then, choose the maximum length prefix or suffix from the remaining string which is a palindrome in itself. Below is the illustration of the approach with the help of an image:
Below is the implementation of the above approach:
Time Complexity: O(N2)
Auxiliary Space: O(N)
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 length of substring whose rotation generates a palindromic substring
- Minimum number of palindromic subsequences to be removed to empty a binary string
- Minimum cuts required to convert a palindromic string to a different palindromic string
- Make palindromic string non-palindromic by rearranging its letters
- Longest Palindromic Substring using Palindromic Tree | Set 3
- Size of smallest subarray to be removed to make count of array elements greater and smaller than K equal
- Minimum number of characters to be removed to make a binary string alternate
- Minimum letters to be removed to make all occurrences of a given letter continuous
- Minimum characters to be replaced to make a string concatenation of a K-length palindromic string
- Generate a string of size N whose each substring of size M has exactly K distinct characters
- Make a palindromic string from given string
- Minimum changes required to make first string substring of second string
- Minimum number of elements to be removed to make XOR maximum
- Minimum number of elements that should be removed to make the array good
- Find the minimum number of elements that should be removed to make an array good
- Minimum digits to be removed to make either all digits or alternating digits same
- Minimum number of edges required to be removed from an Undirected Graph to make it acyclic
- Minimum characters required to be removed to make frequency of each character unique
- Minimum Count of Bit flips required to make a Binary String Palindromic
- Find if a given string can be represented from a substring by iterating the substring “n” times
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.