C++ | String Simulation | Time : O(n), Space : O(1) | Easy code
Please Upvote :)\n\n\nclass Solution {\npublic:\n    bool canChange(string start, string target) {       \n        int l=0,t=0;\n        for(int i=start.length(
Please Upvote :)\n\n```\nclass Solution {\npublic:\n    bool canChange(string start, string target) {       \n        int l=0,t=0;\n        for(int i=start.length()-1;i>=0;i--)\n        {\n            if(start[i]==\'L\')\n                l++;   \n            if(target[i]==\'L\')\n                t++;\n            \n            if(start[i]==\'R\' || target[i]==\'R\')\n            {\n                if(t!=l)\n                    return false;\n            }\n            if(t>l)\n                return false;\n        }\n        if(t!=l)\n            return false;\n        l=0;\n        t=0;\n        for(int i=0;i<start.length();i++)\n        {\n            if(start[i]==\'R\')\n                l++;  \n            if(target[i]==\'R\')\n                t++;\n            \n            if(start[i]==\'L\' || target[i]==\'L\')\n            {\n                if(t!=l)\n                    return false;\n            }\n            if(t>l)\n                return false;\n        }\n        if(t!=l)\n            return false;\n        return true;\n    }\n};\n```
['String', 'C']