human
Count number of indices such that s [ i ] = s [ i + 1 ] : Range queries | Function to create prefix array.
Function to return the result of the query.
Driver Code.
Query 1.
Query 2"
Solution in Python:
 Give me a code to count number of indices such that s [ i ] = s [ i + 1 ] : Range queries and the other steps required?
assistant
#Here is code to count number of indices such that s [ i ] = s [ i + 1 ] : Range queries and the other steps required.
 def preCompute ( n , s , pref ) :
	for i in range ( 1 , n ) :
		pref [ i ] = pref [ i - 1 ]
		if s [ i - 1 ] == s [ i ] :
			pref [ i ] += 1
def query ( pref , l , r ) :
	return pref [ r ] - pref [ l ]
if __name__ == " _ _ main _ _ " :
	s = " ggggggg "
	n = len ( s )
	pref = [ 0 ] * n
	preCompute ( n , s , pref )
	l = 1
	r = 2
	print ( query ( pref , l , r ) )
	l = 1
	r = 5
	print ( query ( pref , l , r ) )