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 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 number of palindromic subsequences to be removed to empty a binary string
- Minimum length of substring whose rotation generates a palindromic substring
- Make palindromic string non-palindromic by rearranging its letters
- Longest Palindromic Substring using Palindromic Tree | Set 3
- Minimum cuts required to convert a palindromic string to a different palindromic string
- 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 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
- Make a palindromic string from given string
- Generate a string of size N whose each substring of size M has exactly K distinct characters
- Minimum changes required to make first string substring of second string
- 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
- Partition given string in such manner that i'th substring is sum of (i-1)'th and (i-2)'th substring
- Longest palindromic string possible after removal of a substring
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.