When solving this, I imagined the dominoes as experiencing "forces" from left and right. Each domino receives a force from the closest 'R' to its left or 'L' to its right. The closer the source, the stronger the force. I assigned a large positive value when a domino was pushed to the right ('R') and a large negative value when pushed to the left ('L'). Then I scanned the string twice:
- Left to Right: I assigned decreasing positive forces after each 'R' and reset after 'L'.
- Right to Left: I assigned decreasing negative forces after each 'L' and reset after 'R'.
Finally, I added the forces at each position: