there n car infinitely long road the car number 0 n 1 leave right car present unique pointyou give 0indexed string direction length n directionsi l R S denote ith car move leave right stay current point respectively each move car speedthe number collision calculate followswhen car move opposite direction collide number collision increase 2when move car collide stationary car number collision increase 1after collision car involve long stay point collide other car change state direction motionreturn total number collision happen road example 1input direction RLRSLLOutput 5explanationthe collision happen road car 0 1 collide since move opposite direction number collision 0 2 2 car 2 3 collide since car 3 stationary number collision 2 1 3 car 3 4 collide since car 3 stationary number collision 3 1 4 car 4 5 collide after car 4 collide car 3 stay point collision hit car 5 the number collision 4 1 5thus total number collision happen road 5 example 2input direction LLRROutput 0explanationno car collide thus total number collision happen road 0 Constraints1 directionslength 105directionsi L R S