
A falling domino exerts no additional force to a falling domino or an already fallen domino.
Let ‘S' be: “R.L”
The second domino is pushed from both directions, therefore remains still.
So the final state becomes “R.L”.
The first line of input contains an integer ‘T’, denoting the number of test cases.
The first line of each test case contains a string ‘S’, representing the initial state of the dominoes.
For each test case, print a single string representing the final state of the dominoes.
Print output of each test case in a separate line.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= |S| <= 10^6
S only contains {‘L’, ‘R’, ‘.’}
Time Limit: 1 sec
For each group of non-falling dominoes, we will have two falling dominoes at the end of each group. There are four cases we need to consider:
Here is the algorithm :
The basic idea is to find the net force on each domino. Using net force, we find how close a domino is to a leftward ‘R’ and a rightward ‘L’, the closer we are, the stronger the force. We start from left to right, our force decreases by 1, and resets to ‘N’ if we meet an ‘R’ direction. Similarly, we move from right to left, we can find closeness to ‘L’.
Here is the algorithm :