Simple Java one pass O(n) solution with explaination
The idea is simple. Just get the non-X characters and compare the positions of them.\n\nclass Solution {\n    public boolean canTransform(String start, String e
The idea is simple. Just get the non-X characters and compare the positions of them.\n```\nclass Solution {\n    public boolean canTransform(String start, String end) {\n        if (!start.replace("X", "").equals(end.replace("X", "")))\n            return false;\n        \n        int p1 = 0;\n        int p2 = 0;\n        \n        while(p1 < start.length() && p2 < end.length()){\n            \n            // get the non-X positions of 2 strings\n            while(p1 < start.length() && start.charAt(p1) == 'X'){\n                p1++;\n            }\n            while(p2 < end.length() && end.charAt(p2) == 'X'){\n                p2++;\n            }\n            \n            //if both of the pointers reach the end the strings are transformable\n            if(p1 == start.length() && p2 == end.length()){\n                return true;\n            }\n            // if only one of the pointer reach the end they are not transformable\n            if(p1 == start.length() || p2 == end.length()){\n                return false;\n            }\n            \n            if(start.charAt(p1) != end.charAt(p2)){\n                return false;\n            }\n            // if the character is 'L', it can only be moved to the left. p1 should be greater or equal to p2.\n            if(start.charAt(p1) == 'L' && p2 > p1){\n                return false;\n            }\n            // if the character is 'R', it can only be moved to the right. p2 should be greater or equal to p1.\n            if(start.charAt(p1) == 'R' && p1 > p2){\n                return false;\n            }\n            p1++;\n            p2++;\n        }\n        return true;\n    }\n    \n}\n```
[]