A solution that moves 'X' if you find this easier to understand.
The move is as follows:\n\n1. X can go through R to move to the left\nRRRX. -> XRRR\n\n2. X can go through L to move to the right\nXLLL -> LLLX\n\nNow go from l
The move is as follows:\n\n1. X can go through R to move to the left\nRRRX. -> XRRR\n\n2. X can go through L to move to the right\nXLLL -> LLLX\n\nNow go from left to right, have counter to save number of \'X\' in end minus number of \'X\' in start\n```\ncount = #\'X\' in end - #\'X\' in start\n```\n\nThere could be two scenarios:\n\n         count > 0 means there\'s an X in start need to move left -> it must go through \'R\' in start, not an \'L\'\n                 i\n         start:  R R X\n         end  :  X R R\n       \n         count < 0 means there\'s an X in start need to move right -> it must go through \'L\' in start, not an \'R\'\n                 i\n         start:  X L L\n         end  :  L L X\n        \n```\nclass Solution {\n    public boolean canTransform(String start, String end) {\n        int n = start.length();\n        \n        //check if R and L count match\n        String s1 = start.replace("X", "");\n        String s2 = end.replace("X", "");\n        if (!s1.equals(s2)) {\n            return false;\n        }\n\t\t\n        // count: go from left to right. Number of X in end - Number of X in start\n        int count = 0; \n        while(i < n) { \n\t\t\t// need to move right through \'L\', but there\'s an \'R\'\n\t\t    if (count < 0 && start.charAt(i) == \'R\') {\n                return false;\n            }\n            if (end.charAt(i) == \'X\') {\n                count++;\n            }\n            if (start.charAt(i) == \'X\') {\n                count--;\n            }\n\t\t\t// need to move left through \'R\', but there\'s an \'L\'\n            if (count > 0 && start.charAt(i) == \'L\') {\n                return false;\n            }            \n            i++;\n        }\n        return true;\n    }\n}\n```
[]