Easy C++ Solution || Basic Loops || Easy To Understand For Begineers || proper Comment
Read the comment for better understanding of the solution\n\n\nclass Solution {\npublic:\n    bool canTransform(string start, string end) {\n        string f,s;
***Read the comment for better understanding of the solution***\n\n```\nclass Solution {\npublic:\n    bool canTransform(string start, string end) {\n        string f,s; // to copy only original pattern from the string         \n        for(int i=0;i<start.size();i++)\n        {\n            if(start[i]!=\'X\') f+=start[i];  //take only elements to check their order\n        }\n        for(int i=0;i<end.size();i++)\n        {\n            if(end[i]!=\'X\') s+=end[i];     // to check the order of second and first string \n        }\n        \n        if(f!=s) return false; // means both the string dont have the equal no. of elements and there is no swap in LR or RL\n        \n        //strat moving with this 2 pointer and check for index of left in both start and end string similarly for \n        int i=0,j=0;\n        while(i<start.size() and j<end.size())\n        {\n            if(start[i]==\'X\') i++; // move if dummy found;\n            else if(end[j]==\'X\') j++; //move if dummy found in end\n            else\n            {\n                if(start[i]==\'L\' and i<j ) return false;     //here the move if LX to XL which is invalid\n                else if(start[i]==\'R\' and i>j) return false; //here the move if XR to RX which is invalid\n                else {\n                    i++;\n                    j++;\n                }\n                \n            }\n        }\n        return true;\n    }\n};\n```
['C', 'C++']