Python O(n) solution with explanation
idea:\n1. each time we saw a L in end string, it means that we must find a L in start (increase the debtL)\n2. each time we saw a R in end string, it means that
idea:\n1. each time we saw a L in end string, it means that we must find a L in start (increase the debtL)\n2. each time we saw a R in end string, it means that we must already found a R in start (decrease the debtR)\n3. in case of RL, L cannot move left of R, so if this L is a matching L, at the time we found this L, the debtR must be zero; similarly, if it\'s a matching R, debtL must be zero\n\nclass Solution:\n    def canTransform(self, start: str, end: str) -> bool:\n\n        n = len(start)\n        debtL = 0\n        debtR = 0\n        \n        for i in range(n):\n            if end[i] == \'L\':\n                debtL += 1\n            elif end[i] == \'R\':\n                debtR -= 1\n                \n            if start[i] == \'L\' and debtR == 0:\n                debtL -= 1\n            elif start[i] == \'R\' and debtL == 0:\n                debtR += 1\n                \n            if debtL < 0 or debtR < 0:\n                return False\n            \n        return debtL == 0 and debtR == 0
[]