BEST OPTIMAL SOLUTION✅✅ || 100% BEATS✅
IntuitionApproachComplexity
Time complexity: O(N)

Space complexity: O(1)
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity: O(N)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    bool canTransform(string st, string res) {
        string s, p;
        for (char c : st){
            if (c != 'X') s += c;
        }
        for (char c : res){
            if (c != 'X') p += c;
        }

        if (s != p){
            return false;
        }
        int i = 0, j = 0, n = st.length();

        while (i < n && j < n){
            while (i<n && st[i] == 'X') i++;
            while (j<n && res[j] == 'X') j++;

            if (i == n && j == n) return true;
            if ((i == n) != (j == n)) return false;

            if (st[i] != res[j]) return false;

            if (st[i] == 'L' && i<j) return false;
            if (st[i] == 'R' && i>j) return false;

            i++;
            j++;
        }
        return true;
    }
};
```
['Two Pointers', 'String', 'String Matching', 'C++']