Simulate how a row of dominoes falls after some are initially pushed left or right.
You are given a string representing a row of dominoes. Each character is one domino state:
Lmeans the domino has been pushed to the leftRmeans the domino has been pushed to the right.means the domino is standing upright
Dominoes continue falling in the direction they are pushed. A standing domino will be pushed by a neighboring falling domino if the force reaches it first. If equal force reaches a domino from both sides at the same time, it stays upright.
Return the final state of the row after all dominoes have settled.
Input Format
- A single string
dominoesconsisting ofL,R, and.. dominoes[i]describes the initial state of thei-th domino.
Output Format
- Return a string of the same length representing the final state after all forces have propagated.
Constraints
1 <= dominoes.length.- The string contains only
L,R, and.. - The answer is unique.
Example 1
Input
dominoes = ".L.R...LR..L.."
Output
"LL.RR.LLRRLL.."
Explanation
The pushes propagate through the upright dominoes. Some sections fall left, some right, and some remain upright when forces balance.
Example 2
Input
dominoes = "RR.L"
Output
"RR.L"
Explanation
The two right-pushed dominoes do not affect the left-pushed domino because the standing domino between them blocks the forces from meeting in a way that changes the final state.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.