JAVA O(N) with Stack
\nclass Solution {\n    public boolean canTransform(String start, String end) {\n        Stack<Integer> L = new Stack(), R = new Stack();\n        for (int i = 
```\nclass Solution {\n    public boolean canTransform(String start, String end) {\n        Stack<Integer> L = new Stack(), R = new Stack();\n        for (int i = 0; i < start.length(); i++) {\n            if (start.charAt(i) == \'R\')\n                R.add(i);\n            if (end.charAt(i) == \'L\')\n                L.add(i);\n            if (start.charAt(i) == \'L\') {\n                if (L.isEmpty() || !R.isEmpty() && L.peek() >= R.peek())\n                    return false;\n                else \n                    L.pop();\n            } \n            if (end.charAt(i) == \'R\') {\n                if (R.isEmpty() || !L.isEmpty() && R.peek() >= L.peek())\n                    return false;\n                else\n                    R.pop();\n            } \n        }\n        if (!L.isEmpty() || !R.isEmpty())\n            return false;\n        return true;\n    }\n}\n```
[]