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. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
In case you wish to attend live classes with industry experts, please refer Geeks Classes Live