human
Length of the longest valid substring | Python3 program to find length of the longest valid substring.
Initialize curMax to zero.
Iterate over the string starting from second index.
Driver Code.
Function call.
Function call"
How can the above be solved in Python?
 Give me a code to length of the longest valid substring and the other steps required?
assistant
#Here is code to length of the longest valid substring and the other steps required.
 def findMaxLen ( s ) :
	if ( len ( s ) <= 1 ) :
		return 0
	curMax = 0
	longest = [ 0 ] * ( len ( s ) )
	for i in range ( 1 , len ( s ) ) :
		if ( ( s [ i ] == ' ) ' and i - longest [ i - 1 ] - 1 >= 0 and s [ i - longest [ i - 1 ] - 1 ] == ' ( ' ) ) :
			longest [ i ] = longest [ i - 1 ] + 2
			if ( i - longest [ i - 1 ] - 2 >= 0 ) :
				longest [ i ] += ( longest [ i - longest [ i - 1 ] - 2 ] )
			else :
				longest [ i ] += 0
			curMax = max ( longest [ i ] , curMax )
	return curMax
if __name__ == ' _ _ main _ _ ' :
	Str = " ( ( ( ) ( ) "
	print ( findMaxLen ( Str ) )
	Str = " ( ) ( ( ) ) ) ) ) "
	print ( findMaxLen ( Str ) )