simple explanation C++ | two pointers
\nclass Solution {\npublic:\n    \n    // * R and L ka order remains unchanged\n    // * L can go only left of X\n    // * R can go only right of X\n    \n    /
```\nclass Solution {\npublic:\n    \n    // * R and L ka order remains unchanged\n    // * L can go only left of X\n    // * R can go only right of X\n    \n    // logic: use two pointers to find positions of L and R (ptr1 for start and ptr2 for end)\n    // the pointers skip all X\'s (consider X\'s as spaces)\n    // after skipping space each time, check if start[ptr1]==end[ptr2] (if not, return false)\n    // as R can move only right, index of R in start must <= index of R in end (think!!)\n    // as L can move only left, index of L in start must be >= index of L in end (think!!)\n    bool canTransform(string start, string end) {\n        if(start.size()==1){\n            if(start[0]==end[0])\n                return true;\n            return false;\n        }\n        \n        int ptr1=0, ptr2=0;\n        while( ptr1<start.size() && ptr2<end.size() ){\n            while(start[ptr1] == \'X\')\n                ptr1++;\n            while(end[ptr2] == \'X\')\n                ptr2++;\n            char a=start[ptr1];\n            char b=end[ptr2];\n            if(a!=b)\n                return false;\n            if(a == \'L\' && ptr1<ptr2)\n                return false;\n            if(a == \'R\' && ptr1>ptr2)\n                return false;\n            ptr1=ptr1+1;\n            ptr2=ptr2+1;\n        }\n        // for remaining spaces in the end (X\'s)\n        while(ptr1<start.size() && start[ptr1]==\'X\')\n            ptr1++;\n        while(ptr2<end.size() && end[ptr2]==\'X\')\n            ptr2++;\n        \n        return ptr1==ptr2;\n    }\n};\n```\n\nreferred from soln of :[https://leetcode.com/problems/swap-adjacent-in-lr-string/discuss/1704920/C++-one-pass-time:O(n)-space:O(1)-(with-explanation)](http://)
['Two Pointers', 'C', 'C++']