human
Maximum length of segments of 0 ' s ▁ and ▁ 1' s | Recursive Function to find total length of the array where 1 is greater than zero.
If reaches till end.
If dp is saved.
Finding for each length.
If the character scanned is 1.
If one is greater than zero , add total length scanned till now.
Continue with next length.
Return the value for start index.
Driver Code.
Size of string.
Calling the function to find the value of function"
How can the above be solved in Python?
 What is a code to maximum length of segments of 0 ' s ▁ and ▁ 1' s and the other steps required?
assistant
#Here is code to maximum length of segments of 0 ' s ▁ and ▁ 1' s and the other steps required.
 def find ( start , adj , n , dp ) :
	if ( start == n ) :
		return 0
	if ( dp [ start ] != - 1 ) :
		return dp [ start ]
	dp [ start ] = 0
	one = 0
	zero = 0
	for k in range ( start , n , 1 ) :
		if ( adj [ k ] == '1' ) :
			one += 1
		else :
			zero += 1
		if ( one > zero ) :
			dp [ start ] = max ( dp [ start ] , find ( k + 1 , adj , n , dp ) + k - start + 1 )
		else :
			dp [ start ] = max ( dp [ start ] , find ( k + 1 , adj , n , dp ) )
	return dp [ start ]
if __name__ == ' _ _ main _ _ ' :
	adj = "100110001010001"
	n = len ( adj )
	dp = [ - 1 for i in range ( n + 1 ) ]
	print ( find ( 0 , adj , n , dp ) )