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
def count ( s ) : NEW_LINE INDENT cnt , ans = 0 , 0 NEW_LINE N = len ( s ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( s [ i ] == ' R ' ) : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT if ( s [ i ] == ' L ' ) : NEW_LINE INDENT ans += cnt NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT s = " RRLL " NEW_LINE print ( count ( s ) ) NEW_LINE