In a string composed of 'L', 'R', and 'X' characters, like "RXXLRXRXL", a move consists of either replacing one occurrence of "XL" with "LX", or replacing one occurrence of "RX" with "XR". Given the starting string start and the ending string end, return True if and only if there exists a sequence of moves to transform one string to the other.

&nbsp;
Example 1:

Input: start = "RXXLRXRXL", end = "XRLXXRRLX"
Output: true
Explanation: We can transform start to end following these steps:
RXXLRXRXL -&gt;
XRXLRXRXL -&gt;
XRLXRXRXL -&gt;
XRLXXRRXL -&gt;
XRLXXRRLX


Example 2:

Input: start = "X", end = "L"
Output: false


&nbsp;
Constraints:


	1 &lt;= start.length&nbsp;&lt;= 104
	start.length == end.length
	Both start and end will only consist of characters in 'L', 'R', and&nbsp;'X'.


class Solution:
    def canTransform(self, start: str, end: str) -> bool:
        def chars(s):
            for i, c in enumerate(s):
                if c != 'X':
                    yield i, c
            
            yield -1, ' '
        
        for (startI, startC), (endI, endC) in zip(chars(start), chars(end)):
            if (startC != endC or
                (startC == 'L' and startI < endI) or
                (startC == 'R' and startI > endI)):
                return False
        
        return True
class Solution {
    public boolean canTransform(String start, String end) {
        int startL = 0, startR = 0;
        int endL = 0, endR = 0;
        String stLR = "", edLR = "";
        for(int i = 0; i < start.length(); i++) {
            if(start.charAt(i) != 'X') {
                if(start.charAt(i) == 'L') {
                    startL++;
                } else{
                    startR++;
                }
                stLR+= start.charAt(i);
            }
            if(end.charAt(i) != 'X') {
                if(end.charAt(i) == 'L') {
                    endL++;
                } else{
                    endR++;
                }
                edLR += end.charAt(i);
            }

            if(startL > endL || startR < endR) //Check conditions at each instant
                return false;
        }

        if(startL != endL || startR != endR || !stLR.equals(edLR)) //check their final count and positions
            return false;

        return true;
    }

}
class Solution {
public:
    bool canTransform(string start, string end) {
        int s=0,e=0;
        while(s<=start.size() and e<=end.size()){
            while(s<start.size() and start[s]=='X'){
                s++;
            }
            while(e<end.size() and end[e]=='X'){
                e++;
            }
            if(s==start.size() or e==end.size()){
                return s==start.size() and e==end.size();
            } else if(start[s]!=end[e]){
                return false;
            } else if(start[s]=='R' and e<s){
                return false;
            } else if(start[s]=='L' and e>s){
                return false;
            }
            s++;
            e++;
        }
        return true;
    }
};
/**
 * @param {string} start
 * @param {string} end
 * @return {boolean}
 */
var canTransform = function(start, end) {
    let i = 0;
    let j = 0;

    while (i < start.length || j < end.length) {
        if (start[i] === 'X') {
            i++;
            continue;
        }

        if (end[j] === 'X') {
            j++;
            continue;
        }

        // Breaking (1)
        if (start[i] !== end[j]) return false;

        // Breaking (2)
        if (start[i] === 'R' && i > j) return false;

        // Breaking (3)
        if (start[i] === 'L' && j > i) return false;

        i++;
        j++;
    }

    return true;
};
Swap Adjacent in LR String