human
Maximum length palindromic substring such that it starts and ends with given char | Function that returns true if str [ i ... j ] is a palindrome.
Function to return the length of the longest palindromic sub - string such that it starts and ends with the character ch.
If current character is a valid starting index.
Instead of finding the ending index from the beginning , find the index from the end This is because if the current sub - string is a palindrome then there is no need to check the sub - strings of smaller length and we can skip to the next iteration of the outer loop.
If current character is a valid ending index.
If str [ i ... j ] is a palindrome then update the length of the maximum palindrome so far.
Driver code"
Solution in Python:
 Write me a code to maximum length palindromic substring such that it starts and ends with given char and the other steps required?
assistant
#Here is code to maximum length palindromic substring such that it starts and ends with given char and the other steps required.
 def isPalindrome ( str , i , j ) :
	while ( i < j ) :
		if ( str [ i ] != str [ j ] ) :
			return False ;
		i += 1 ;
		j -= 1 ;
	return True ;
def maxLenPalindrome ( str , n , ch ) :
	maxLen = 0 ;
	for i in range ( n ) :
		if ( str [ i ] == ch ) :
			for j in range ( n - 1 , i + 1 , - 1 ) :
				if ( str [ j ] == ch ) :
					if ( isPalindrome ( str , i , j ) ) :
						maxLen = max ( maxLen , j - i + 1 ) ;
						break ;
	return maxLen ;
str = " lapqooqpqpl " ;
n = len ( str ) ;
ch = ' p ' ;
print ( maxLenPalindrome ( str , n , ch ) ) ;