There are directions of length directions[i] denotes the initial state of the car at index i:
'L' indicates that the car is moving left.
'R' indicates that the car is moving right.
'S' indicates that the car is stationary.
All moving cars travel at the same constant speed.
Collisions occur based on the following conditions:
If a car moving right collides with a car moving left, the total number of collisions increases by
If a moving car collides with a stationary car, the total number of collisions increases by
Once a car becomes stationary, it remains at that position on the road.
Return the total number of collisions that occur on the road.
Constraints:
directions.length
directions[i] is either 'L', 'R', or 'S'.
There are directions of length directions[i] denotes the initial state of the car at index i:
'L' indicates that the car is moving left.
'R' indicates that the car is moving right.
'S' indicates that the car is stationary.
All moving cars travel at the same constant speed.
Collisions occur based on the following conditions:
If a car moving right collides with a car moving left, the total number of collisions increases by
If a moving car collides with a stationary car, the total number of collisions increases by
Once a car becomes stationary, it remains at that position on the road.
Return the total number of collisions that occur on the road.
Constraints:
directions.length
directions[i] is either 'L', 'R', or 'S'.