human
Longest substring of 0 s in a string formed by k concatenations | Function to calculate maximum length of substring containing only zero.
loop to calculate longest substring in string containing 0 's.
if all elements in string a are '0.
Else , find prefix and suffix containing only zeroes.
Calculate length of the prefix containing only zeroes.
Calculate length of the suffix containing only zeroes.
if k <= 1 , no need to take suffix + prefix into account.
Driver program to test above function"
How can the above be solved in Python?
assistant
#Here is code to longest substring of 0 s in a string formed by k concatenations and the other steps required.
 def subzero ( str , k ) :
	ans = 0
	curr = 0
	n = len ( str )
	for i in str :
		if ( i == '0' ) :
			curr += 1
		else :
			curr = 0
		ans = max ( ans , curr )
'
	if ( ans == n ) :
		print ( n * k )
		return
	else :
		pre = suff = 0
		for i in str :
			if ( i == '0' ) :
				pre += 1
			else :
				break
		for i in range ( n - 1 , - 1 , - 1 ) :
			if ( str [ i ] == '0' ) :
				suff += 1
			else :
				break
	if ( k > 1 ) :
		ans = max ( ans , pre + suff )
	print ( ans )
	return
k = 5
str = '00100110'
subzero ( str , k )