human
Length of longest consecutive ones by at most one swap in a Binary String | Function to calculate the length of the longest consecutive 1 's.
To count all 1 's in the string.
To store cumulative 1 's.
Counting cumulative 1 's from left.
If 0 then start new cumulative one from that i.
perform step 3 of the approach.
step 3.
Driver Code.
string"
Solution in Python:

Write me a code to length of longest consecutive ones by at most one swap in a Binary String and the other steps required?
assistant
#Here is code to length of longest consecutive ones by at most one swap in a Binary String and the other steps required.
 def maximum_one ( s , n ) :
	cnt_one = 0
	cnt , max_cnt = 0 , 0
	for i in range ( n ) :
		if ( s [ i ] == '1' ) :
			cnt_one += 1
			cnt += 1
		else :
			max_cnt = max ( max_cnt , cnt )
			cnt = 0
	max_cnt = max ( max_cnt , cnt )
	left = [ 0 ] * n
	right = [ 0 ] * n
	if ( s [ 0 ] == '1' ) :
		left [ 0 ] = 1
	else :
		left [ 0 ] = 0
	if ( s [ n - 1 ] == '1' ) :
		right [ n - 1 ] = 1
	else :
		right [ n - 1 ] = 0
	for i in range ( 1 , n ) :
		if ( s [ i ] == '1' ) :
			left [ i ] = left [ i - 1 ] + 1
		else :
			left [ i ] = 0
	for i in range ( n - 2 , - 1 , - 1 ) :
		if ( s [ i ] == '1' ) :
			right [ i ] = right [ i + 1 ] + 1
		else :
			right [ i ] = 0
	for i in range ( 1 , n - 1 ) :
		if ( s [ i ] == '0' ) :
			sum = left [ i - 1 ] + right [ i + 1 ]
			if ( sum < cnt_one ) :
				max_cnt = max ( max_cnt , sum + 1 )
			else :
				max_cnt = max ( max_cnt , sum )
	return max_cnt
if __name__ == " _ _ main _ _ " :
	s = "111011101"
	print ( maximum_one ( s , len ( s ) ) )