human
Count subsequences 01 in string generated by concatenation of given numeric string K times | Function to calculate the number of subsequences of "01".
Store count of 0 ' s ▁ and ▁ 1' s.
Count of subsequences without concatenation.
Case 1.
Case 2.
Return the total count.
Driver Code"
Solution in Python:
assistant
#Here is code to count subsequences 01 in string generated by concatenation of given numeric string K times and the other steps required.
 def countSubsequence ( S , N , K ) :
	C = 0
	C1 = 0
	C0 = 0
	for i in range ( 0 , N ) :
		if ( S [ i ] == '1' ) :
			C1 += 1
		elif ( S [ i ] == '0' ) :
			C0 += 1
	B1 = 0
	for i in range ( 0 , N ) :
		if ( S [ i ] == '1' ) :
			B1 += 1
		elif ( S [ i ] == '0' ) :
			C = C + ( C1 - B1 )
	ans = C * K
	ans += ( C1 * C0 * ( ( ( K ) * ( K - 1 ) ) // 2 ) )
	return ans
if __name__ == " _ _ main _ _ " :
	S = "230013110087"
	K = 2
	N = len ( S )
	print ( countSubsequence ( S , N , K ) )