C++ O(n) time  | O(1) space | Explained with examples
Rules: \nXL -> LX\nRX -> XR\nRL is a deadline.(incase it dosen\'t match with \'end\')\nSo check for dangling \'R\' to the right side of \'RL\' (i.e an R not fol
Rules: \nXL -> LX\nRX -> XR\nRL is a deadline.(incase it dosen\'t match with \'end\')\nSo check for dangling \'R\' to the right side of \'RL\' (i.e an R not followed by an \'X\' and not matching with end[i])\n***Something like : "XRLXR" and "RXXLL"***\nFor finding unpaired \'L\' iterate from the end, check for a dangling \'L\' (i.e an \'L\' to the left of \'RX\' where the \'L\' is not preceded by an \'X\' and not matching with end[i])\n***Something like : "LXRLX" and "RRXXL"***\n```\nclass Solution {\npublic:\n    bool canTransform(string start, string end) {\n        if(start.length()!=end.length()) \n            return 0;\n        int count =0;\n        for(int i=0;i<start.length();i++) {\n            if(start[i]==\'R\')\n            {\n                count++;\n            }\n            if(end[i]==\'R\') {\n                if(--count<0) \n                    return 0;\n            }\n            else if(end[i]==\'L\' && count!=0)\n                return 0;\n        }\n        if(count!=0) \n            return 0;\n        for(int i=start.size();i>=0;i--) {\n            if(start[i]==\'L\') \n                count++;\n            if(end[i]==\'L\') {\n                if(--count<0)\n                    return 0;\n            }\n            else if(end[i]==\'R\' && count!=0)\n                return 0;\n        }\n        return count==0;\n    }\n};\n```
['C', 'C++']