human
What is a code to find total no of collisions taking place between the balls in which initial direction of each ball is given and the other steps required given the following:
Find total no of collisions taking place between the balls in which initial direction of each ball is given | Function to count no of collision.
Length of the string.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to find total no of collisions taking place between the balls in which initial direction of each ball is given and the other steps required.
 def count ( s ) :
	cnt , ans = 0 , 0
	N = len ( s )
	for i in range ( N ) :
		if ( s [ i ] == ' R ' ) :
			cnt += 1
		if ( s [ i ] == ' L ' ) :
			ans += cnt
	return ans
s = " RRLL "
print ( count ( s ) )