class Solution:
    def pushDominoes(self, dominoes):
        dominoes = list(dominoes)
        right, left = set(), set()
        n = len(dominoes)
        for i in range(len(dominoes)):
            if dominoes[i]=="R":
                right.add(i)
            elif dominoes[i]=="L":
                left.add(i)
        while right or left:
            new_right, new_left = set(), set()
            for num in right:
                if num+2<n:
                    if num+2 not in left and dominoes[num+1]==".":
                        dominoes[num+1]="R"
                        new_right.add(num+1)
                elif num == n-2 and dominoes[num+1]==".":
                    dominoes[num + 1] = "R"

            for num in left:
                if num-2>=0:
                    if num-2 not in right and dominoes[num-1]==".":
                        dominoes[num-1]="L"
                        new_left.add(num-1)
                elif num == 1 and dominoes[0] == ".":
                    dominoes[0]="L"
            right, left = new_right, new_left
        return ''.join(x for x in dominoes)
        