human
Queries to flip characters of a binary string in given range | Function to find the binary by performing all the given queries.
Stores length of the string.
prefixCnt [ i ] : Stores number of times strr [ i ] toggled by performing all the queries.
Update prefixCnt [ Q [ i ] [ 0 ] ].
Update prefixCnt [ Q [ i ] [ 1 ] + 1 ].
Calculate prefix sum of prefixCnt [ i ].
Traverse prefixCnt [ ] array.
If ith element toggled odd number of times.
Toggled i - th element of binary string.
Driver Code"
Solution in Python:
 Give me a code to queries to flip characters of a binary string in given range and the other steps required?
assistant
#Here is code to queries to flip characters of a binary string in given range and the other steps required.
 def toggleQuery ( strr , Q , M ) :
	strr = [ i for i in strr ]
	N = len ( strr )
	prefixCnt = [ 0 ] * ( N + 1 )
	for i in range ( M ) :
		prefixCnt [ Q [ i ] [ 0 ] ] += 1
		prefixCnt [ Q [ i ] [ 1 ] + 1 ] -= 1
	for i in range ( 1 , N + 1 ) :
		prefixCnt [ i ] += prefixCnt [ i - 1 ]
	for i in range ( N ) :
		if ( prefixCnt [ i ] % 2 ) :
			strr [ i ] = ( chr ( ord ( '1' ) - ord ( strr [ i ] ) + ord ( '0' ) ) )
	return " " . join ( strr )
if __name__ == ' _ _ main _ _ ' :
	strr = "101010" ;
	Q = [ [ 0 , 1 ] , [ 2 , 5 ] , [ 2 , 3 ] , [ 1 , 4 ] , [ 0 , 5 ] ]
	M = len ( Q )
	print ( toggleQuery ( strr , Q , M ) )