Easy-to-understand explanation with PICTURE
\nBetter formatted original blog post here\n\n## Key observations:\nThere are three kinds of characters, \u2018L\u2019, \u2018R\u2019, \u2018X\u2019.\nReplacing
\n[Better formatted original blog post here](https://medium.com/@algo.monster.hello/leetcode-777-swap-adjacent-in-lr-string-google-interview-question-3574d2c77d19)\n\n## Key observations:\nThere are three kinds of characters, \u2018L\u2019, \u2018R\u2019, \u2018X\u2019.\nReplacing XL with LX = move L to the left by one\nReplacing RX with XR = move R to the right by one\nIf we remove all the X in both strings, the resulting strings should be the same.\n## Additional observations:\nSince a move always involves X, an L or R cannot move through another L or R.\nSince an L can only move to the right, for each occurrence of L in the start string, its position should be to the same or to the left of its corresponding L in the end string.\n\n![image](https://assets.leetcode.com/users/images/8c1c2572-00a8-4413-8383-ec5d5126c060_1601526675.9118004.png)\n\nAnd vice versa for the R characters.\n\n## Implementation\n\nWe first compare two strings with X removed. This checks relative position between Ls and Rs are correct.\n\nThen we find the indices for each occurence of L and check the condition in the above figure. Then we do the same for R.\n\n```python\nclass Solution:\n    def canTransform(self, start: str, end: str) -> bool:\n        if len(start) != len(end): return False\n        \n        # check L R orders are the same\n        if start.replace(\'X\',\'\') != end.replace(\'X\', \'\'): return False\n        \n        n = len(start)\n        Lstart = [i for i in range(n) if start[i] == \'L\']\n        Lend = [i for i in range(n) if end[i] == \'L\']\n        \n        Rstart = [i for i in range(n) if start[i] == \'R\']\n        Rend = [i for i in range(n) if end[i] == \'R\']\n\t\t# check L positions are correct\n        for i, j in zip(Lstart, Lend):\n            if i < j:\n                return False\n            \n        # check R positions are correct\n        for i, j in zip(Rstart, Rend):\n            if i > j:\n                return False\n            \n        return True\n```\n\n[Better formatted original post and solutions and patterns ](https://medium.com/@algo.monster.hello/leetcode-777-swap-adjacent-in-lr-string-google-interview-question-3574d2c77d19)
['Python']