human
Count of substrings of a binary string containing K ones | method returns total number of substring having K ones.
initialize index having zero sum as 1.
loop over binary characters of string.
update countOfOne variable with value of ith character.
if value reaches more than K , then update result.
add frequency of indices , having sum ( current sum - K ) , to the result.
update frequency of one 's count.
Driver code"
Solution in Python:
 Can you provide a code to count of substrings of a binary string containing K ones and the other steps required?
assistant
#Here is code to count of substrings of a binary string containing K ones and the other steps required.
 def countOfSubstringWithKOnes ( s , K ) :
	N = len ( s )
	res = 0
	countOfOne = 0
	freq = [ 0 for i in range ( N + 1 ) ]
	freq [ 0 ] = 1
	for i in range ( 0 , N , 1 ) :
		countOfOne += ord ( s [ i ] ) - ord ( '0' )
		if ( countOfOne >= K ) :
			res += freq [ countOfOne - K ]
		freq [ countOfOne ] += 1
	return res
if __name__ == ' _ _ main _ _ ' :
	s = "10010"
	K = 1
	print ( countOfSubstringWithKOnes ( s , K ) )