human
Minimum size substring to be removed to make a given string palindromic | Function to find palindromic prefix of maximum length.
Finding palindromic prefix of maximum length.
Checking if curr substring is palindrome or not ..
Condition to check if the prefix is a palindrome.
if no palindrome exist.
Function to find the maximum size palindrome such that after removing minimum size substring.
Finding prefix and suffix of same length.
Matching the ranges.
Case 1 : Length is even and whole string is palindrome.
Case 2 : Length is odd and whole string is palindrome.
Adding that mid character.
Add prefix or suffix of the remaining string or suffix , whichever is longer.
Reverse the remaining string to find the palindromic suffix.
Driver Code"
Solution in Python:
 What is a code to minimum size substring to be removed to make a given string palindromic and the other steps required?
assistant
#Here is code to minimum size substring to be removed to make a given string palindromic and the other steps required.
 def palindromePrefix ( S ) :
	n = len ( S )
	for i in range ( n - 1 , - 1 , - 1 ) :
		curr = S [ 0 : i + 1 ]
		l = 0
		r = len ( curr ) - 1
		is_palindrome = 1
		while ( l < r ) :
			if ( curr [ l ] != curr [ r ] ) :
				is_palindrome = 0
				break
			l += 1
			r -= 1
		if ( is_palindrome ) :
			return curr
	return " "
def maxPalindrome ( S ) :
	n = len ( S )
	if ( n <= 1 ) :
		return S
	pre = " "
	suff = " "
	i = 0
	j = n - 1
	while ( S [ i ] == S [ j ] and i < j ) :
		i += 1
		j -= 1
	i -= 1
	j += 1
	pre = S [ 0 : i + 1 ]
	suff = S [ j : ]
	if ( j - i == 1 ) :
		return pre + suff
	if ( j - i == 2 ) :
		mid_char = S [ i + 1 : i + 2 ]
		return pre + mid_char + suff
	rem_str = S [ i + 1 : j ]
	pre_of_rem_str = palindromePrefix ( rem_str )
	list1 = list ( rem_str )
	list1 . reverse ( )
	rem_str = ' ' . join ( list1 )
	suff_of_rem_str = palindromePrefix ( rem_str )
	if ( len ( pre_of_rem_str ) >= len ( suff_of_rem_str ) ) :
		return ( pre + pre_of_rem_str + suff )
	else :
		return ( pre + suff_of_rem_str + suff )
if __name__ == " _ _ main _ _ " :
	S = " geeksforskeeg "
	print ( maxPalindrome ( S ) )