Easy C++ | Stack | Greedy Approach | O(n)
Simple Stack Solution given below:\n\n\nclass Solution {\npublic:\n    bool canChange(string s1, string s2) {\n        stack<pair<char, int>> st1, st2;\n       
Simple Stack Solution given below:\n\n```\nclass Solution {\npublic:\n    bool canChange(string s1, string s2) {\n        stack<pair<char, int>> st1, st2;\n        int i, n = s1.size();\n        for(i=0; i<n; i++)\n        {\n            if(s1[i]==\'L\')\n            {\n                st1.push({\'L\', i});\n            }\n            else if(s1[i]==\'R\')\n            {\n                st1.push({\'R\', i});\n            }\n            if(s2[i]==\'L\')\n            {\n                st2.push({\'L\', i});\n            }\n            else if(s2[i]==\'R\')\n            {\n                st2.push({\'R\', i});\n            }\n        }\n        \n        // If number of L\'s and R\'s in st1 and st2 are not same \n        if(st1.size() != st2.size())\n        {\n            return false;\n        }\n        while(!st1.empty() and !st2.empty())\n        {\n            // If the sequence is not same, then it is always impossible\n            if(st1.top().first != st2.top().first)\n            {\n                return false;\n            }\n            \n            if(st1.top().first == \'R\')\n            {\n                // If R in s1 is ahead of R in target string, then we can never move it towards the left\n                // Therefore, it is always impossible\n                if(st1.top().second > st2.top().second)\n                {\n                    return false;\n                }\n            }\n            else\n            {\n                // If L in s1 is before of L in target string, then we can never move it towards the right\n                // Therefore, it is always impossible\n                if(st1.top().second < st2.top().second)\n                {\n                    return false;\n                }\n            }\n            st1.pop();\n            st2.pop();\n        }\n        return true;\n    }\n};\n```
['Stack', 'Greedy', 'C', 'C++']