human
Can you provide a code to longest Palindrome in a String formed by concatenating its prefix and suffix and the other steps required given the following:
Longest Palindrome in a String formed by concatenating its prefix and suffix | Function to check whether the string is a palindrome.
Reverse the string to compare with the original string.
Check if both are same.
Function to find the longest palindrome in a string formed by concatenating its prefix and suffix.
Length of the string.
Finding the length upto which the suffix and prefix forms a palindrome together.
Check whether the string has prefix and suffix substrings which are palindromes ..
Removing the suffix and prefix substrings which already forms a palindrome and storing them in separate strings.
Check all prefix substrings in the remaining string str.
Check if the prefix substring is a palindrome.
If the prefix substring is a palindrome then check if it is of maximum length so far.
Check all the suffix substrings in the remaining string str.
Check if the suffix substring is a palindrome.
If the suffix substring is a palindrome then check if it is of maximum length so far.
Combining all the thee parts of the answer.
Driver code"
Solution in Python:
assistant
#Here is code to longest Palindrome in a String formed by concatenating its prefix and suffix and the other steps required.
 def isPalindrome ( r ) :
	p = r
	p = " " . join ( reversed ( p ) )
	return ( r == p )
def PrefixSuffixPalindrome ( st ) :
	n = len ( st )
	length = 0
	for i in range ( n // 2 ) :
		if ( st [ i ] != st [ n - i - 1 ] ) :
			length = i
			break
	prefix = " "
	suffix = " "
	midPal = " "
	prefix = st [ : length ]
	suffix = st [ n - length : ]
	st = st [ length : n - 2 * length + length ]
	for i in range ( 1 , len ( st ) + 1 ) :
		y = st [ 0 : i ]
		if ( isPalindrome ( y ) ) :
			if ( len ( midPal ) < len ( y ) ) :
				midPal = y
	for i in range ( 1 , len ( st ) + 1 ) :
		y = st [ len ( st ) - i ]
		if ( isPalindrome ( y ) ) :
			if ( len ( midPal ) < len ( y ) ) :
				midPal = y
	answer = prefix + midPal + suffix
	return answer
if __name__ == " _ _ main _ _ " :
	st = " abcdfdcecba " ;
	print ( PrefixSuffixPalindrome ( st ) )