human
Count of sub | Function to find the count of substrings with equal no . of consecutive 0 ' s ▁ and ▁ 1' s.
To store the total count of substrings.
Traversing the string.
Count of consecutive 0 ' s ▁ & ▁ 1' s.
Counting subarrays of type "01".
Count the consecutive 0 's.
If consecutive 0 ' s ▁ ▁ ends ▁ then ▁ check ▁ for ▁ ▁ consecutive ▁ 1' s.
Counting consecutive 1 's.
Counting subarrays of type "10".
Count consecutive 1 's.
If consecutive 1 ' s ▁ ▁ ends ▁ then ▁ check ▁ for ▁ ▁ consecutive ▁ 0' s.
Count consecutive 0 's.
Update the total count of substrings with minimum of ( cnt0 , cnt1 ).
Return answer.
Driver code.
Function to print the count of substrings"
How can the above be solved in Python?
 ... Give me a code to count of sub and the other steps required?
assistant
#Here is code to count of sub and the other steps required.
 def countSubstring ( S , n ) :
	ans = 0 ;
	i = 0 ;
	while ( i < n ) :
		cnt0 = 0 ; cnt1 = 0 ;
		if ( S [ i ] == '0' ) :
			while ( i < n and S [ i ] == '0' ) :
				cnt0 += 1 ;
				i += 1 ;
			j = i ;
			while ( j < n and S [ j ] == '1' ) :
				cnt1 += 1 ;
				j += 1 ;
		else :
			while ( i < n and S [ i ] == '1' ) :
				cnt1 += 1 ;
				i += 1 ;
			j = i ;
			while ( j < n and S [ j ] == '0' ) :
				cnt0 += 1 ;
				j += 1 ;
		ans += min ( cnt0 , cnt1 ) ;
	return ans ;
if __name__ == " _ _ main _ _ " :
	S = "0001110010" ;
	n = len ( S ) ;
	print ( countSubstring ( S , n ) ) ;