Simple C++ Easy Solution | Faster than 100% | O(N)
\nObservation 1:\nEx- _ L _ R _ _ R _ L\nLook at the example and imagine _ moving . We will notice that _ pushes L to left and it pushes R to right.\n\nWe can r
\n**Observation 1:**\nEx- _ L _ R _ _ R _ L\nLook at the example and imagine _ moving . We will notice that _ pushes L to left and it pushes R to right.\n\nWe can remove all the spaces and store the new string in s(start string without _ ) and t(target string without _ ), if s!=t the answer is false as L and R cannot cross each other so there\'s no way to make start==target.\n\n**Observation 2:**\n_ will move L only towards left, so if the index of L in start is lesser than L in target, then it is not possible to make the strings equal.\nSo in a vector(l1) we store all the indexes where start[i]=\'L\' and in another vector(l2) we store all the indexes where target[i]==\'L\'. Then we loop the vector and if at any index l1[i]<l2[i] we return false.\n\n**Observation 3:**\nSimilarly, _ will move R only towards right, so if the index of R in start is greater than R in target, then it is not possible to make the strings equal.\nSo in a vector(r1) we store all the indexes where start[i]=\'R\' and in another vector(r2) we store all the indexes where target[i]==\'R\'. Then we loop the vector and if at any index r1[i]>r2[i] we return false.\n\nCode:\n```\nclass Solution {\npublic:\n    bool canChange(string start, string target) {\n        string s,t;\n        for(int i=0;i<start.size();i++){\n            if(start[i]!=\'_\')s.push_back(start[i]);\n            if(target[i]!=\'_\')t.push_back(target[i]);\n        }\n        if(s!=t)return false;\n        vector<int> l1,l2;\n        for(int i=0;i<start.size();i++){\n            if(start[i]==\'L\')l1.push_back(i);\n            if(target[i]==\'L\')l2.push_back(i);\n        }\n        for(int i=0;i<l1.size();i++){\n            if(l1[i]<l2[i])return false;\n        }\n        vector<int> r1,r2;\n        for(int i=0;i<start.size();i++){\n            if(start[i]==\'R\')r1.push_back(i);\n            if(target[i]==\'R\')r2.push_back(i);\n        }\n        for(int i=0;i<r1.size();i++){\n            if(r1[i]>r2[i])return false;\n        }\n        return true;\n    }\n};\n```\nPlease Upvote if you found it useful!\n
['Greedy', 'C']