human
Length of Longest Palindrome Substring | Function to find the length of the longest palindromic subString.
Length of String str.
Stores the dp states.
All subStrings of length 1 are palindromes.
Check for sub - String of length 2.
If adjacent character are same.
Update table [ i ] [ i + 1 ].
Check for lengths greater than 2 k is length of subString.
Fix the starting index.
Ending index of subString of length k.
Check for palindromic subString str [ i , j ].
Mark True.
Update the maximum length.
Return length of LPS.
Driver Code.
Given String str.
Function Call"
How can the above be solved in Python?
assistant
#Here is code to length of Longest Palindrome Substring and the other steps required.
 def longestPalSubstr ( str ) :
	n = len ( str ) ;
	table = [ [ False for i in range ( n ) ] for j in range ( n ) ] ;
	maxLength = 1 ;
	for i in range ( n ) :
		table [ i ] [ i ] = True ;
	start = 0 ;
	for i in range ( n - 1 ) :
		if ( str [ i ] == str [ i + 1 ] ) :
			table [ i ] [ i + 1 ] = True ;
			start = i ;
			maxLength = 2 ;
	for k in range ( 3 , n + 1 ) :
		for i in range ( n - k + 1 ) :
			j = i + k - 1 ;
			if ( table [ i + 1 ] [ j - 1 ] and str [ i ] == str [ j ] ) :
				table [ i ] [ j ] = True ;
				if ( k > maxLength ) :
					start = i ;
					maxLength = k ;
	return maxLength ;
if __name__ == ' _ _ main _ _ ' :
	str = " forgeeksskeegfor " ;
	print ( longestPalSubstr ( str ) ) ;