human
Count of substrings of a given Binary string with all characters same | Function to count number of sub - strings of a given binary string that contains only 1.
Iterate untill L and R cross each other.
Check if reached the end of string.
Check if encountered '1' then extend window.
Check if encountered '0' then add number of strings of current window and change the values for both l and r.
Return the answer.
Function to flip the bits of string.
Function to count number of sub - strings of a given binary string that contains only 0 s & 1 s.
count of substring which contains only 1 s.
Flip the character of string s 0 to 1 and 1 to 0 to count the substring with consecutive 0 s.
count of substring which contains only 0 s.
Driver Code.
Given string str.
Function Call"
Solution in Python:

=====
Can you provide a code to count of substrings of a given Binary string with all characters same and the other steps required?
assistant
#Here is code to count of substrings of a given Binary string with all characters same and the other steps required.
 def countSubAllOnes ( s ) :
	l , r , ans = 0 , 0 , 0
	while ( l <= r ) :
		if ( r == len ( s ) ) :
			ans += ( ( r - l ) * ( r - l + 1 ) ) // 2
			break
		if ( s [ r ] == '1' ) :
			r += 1
		else :
			ans += ( ( r - l ) * ( r - l + 1 ) ) // 2
			l = r + 1
			r += 1
	return ans
def flip ( s ) :
	arr = list ( s )
	for i in range ( len ( s ) ) :
		if ( arr [ i ] == '1' ) :
			arr [ i ] = '0'
		else :
			arr [ i ] = '1'
	s = ' ' . join ( arr )
	return s
def countSubAllZerosOnes ( s ) :
	only_1s = countSubAllOnes ( s )
	s = flip ( s )
	only_0s = countSubAllOnes ( s )
	return only_0s + only_1s
if __name__ == " _ _ main _ _ " :
	s = "011"
	print ( countSubAllZerosOnes ( s ) )