Python One Pass O(N) Time O(1) Space
Observations:\n1. R can only be moved to right\n2. L can only be moved to left\n3. Relative order of R and L cannot be changed\n\nThus, at any given index i, nu
Observations:\n1. R can only be moved to right\n2. L can only be moved to left\n3. Relative order of R and L cannot be changed\n\nThus, at any given index `i`, number R in `start[:i+1]` >= in ` end[:i+1]`, number of L in `start[:i+1]` <= in `end[:i+1]`. \n\nSolution: go thru start and end from left to right, maintain two variables and both variables must be non-negative all the time (recall the observations above).\n\n+ `count_R`: count of R in `start[:i+1]` - count of R in `end[:i+1]`\n+ `count_L`: count of L in `end[:i+1]` - count of L in `start[:i+1]`\n\nBesides, when we are waiting for a L in `start` (`count_L` > 0), we must see next L before next R in `start` (observation 3). Similarly, when we are waiting for a R in `end` (`count_R` > 0), we must see next R before next L in `end`.\n\n```\nclass Solution:\n    def canTransform(self, start: str, end: str) -> bool:\n        count_R = count_L = 0\n\t\t\n        for i in range(len(start)):\n            if start[i] == \'R\':\n                if count_L > 0:\n                    return False\n                count_R += 1\n            if end[i] == \'R\':\n                count_R -= 1\n                if count_R < 0:\n                    return False\n            if end[i] == \'L\':\n                if count_R > 0:\n                    return False\n                count_L += 1\n            if start[i] == \'L\':\n                count_L -= 1\n                if count_L < 0: \n                    return False\n        if count_R or count_L:\n            return False\n        return True\n```
['Python']