General Approach || Faster than 100%
Problem: We have two strings S and T. We want to achieve T from S by moving characters of S.\n\n##### Conditions that must hold:\n Size of strings must be same.
**Problem:** We have two strings S and T. We want to achieve T from S by moving characters of S.\n\n##### Conditions that must hold:\n* *Size of strings must be same.*\n* *Frequency of characters must be same.*\n\n##### Movements:\n* **CASE 1:** If characters can cross each other, then the above two conditions are enough.\n* **CASE 2:** If characters have restricted movements (like in this question), then the presence of characters in S should be in accordance with the restrictions.\n\n##### CASE 2 Explanation:\nLet the allowed movement says that the characters can\'t cross each other. It means, the ordering of the characters in S and T must also be same. In simple words, S = T. Very simple! That\'s why the question is allowing movements through \' _ \'. \n\nLet\'s come to the original question. \n**Movement Restrictions:** \'L\' can move only to the left and \'R\' can move only to the right. And \'L\' and \'R\' cannot cross each other.\n\nSince \'L\' and \'R\' can\'t cross each other, so if we create strings of \'L\' and \'R\' only, then that strings must be equal (say S_ = T_).\n\nSince \'L\' can move only to the left and \'R\' can move only to the right, therefore \'L\' should be in the right of required position and \'R\' should be in the left of required position in the string S_.\n\n\n**C++ implementation of the above approach:**\n\n```\nclass Solution {\npublic:\n    bool canChange(string s, string t) {\n        string s_, t_; // strings of L and R only\n        vector<int> si, ti; // Corresponding indices of L and R.\n        for(int i = 0; i < s.size(); i++) {\n            if(s[i] == \'L\' or s[i] == \'R\') {\n                s_.push_back(s[i]);\n                si.push_back(i);\n            }\n            if(t[i] == \'L\' or t[i] == \'R\') {\n                t_.push_back(t[i]);\n                ti.push_back(i);\n            }\n        }\n        if(s_ != t_) return false; // Ordering must be same.\n        for(int i = 0; i < t_.size(); i++) {\n            // L should be at or in the right of required position.\n            if(t_[i] == \'L\' and si[i] < ti[i]) return false; // L is in left.\n            // R should be at or in the left of required position.\n            if(t_[i] == \'R\' and si[i] > ti[i]) return false; // R is in right.\n        }\n        return true;\n    }\n};\n```\n\n**Runtime:** 89ms\n\n\n\n
['String']