Minimum size substring to be removed to make a given string palindromic
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)