Beats 50% People
Intuition\nI have used 2 Pointer but used so much If and else conditions may be this code will be beginner friendly.\n\n# Approach\n2 Pointer\n\n# Complexity\n-
# Intuition\nI have used 2 Pointer but used so much If and else conditions may be this code will be beginner friendly.\n\n# Approach\n2 Pointer\n\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(1)\n\n# Code\n```java []\nclass Solution {\n    public boolean canChange(String start, String target) {\n\n        int n = start.length();\n        int i =0 , j =0 ;\n        for( ; i < n && j <n ;){\n            char sc = start.charAt(i);\n            char tc = target.charAt(j);\n            if(sc == tc){\n                if(sc == \'L\' && i < j) {\n                    return false;\n                }\n                else if(sc == \'R\' && j < i){\n                    return false;\n                }\n                else{\n                    i++;\n                    j++;\n                }\n            }\n            else if(tc == \'L\' && j > i){\n                return false;\n            } \n            else if(sc == \'R\' && i > j){\n                return false;\n            }\n            else if(tc == \'L\' && sc == \'_\'){\n                i++;\n            }\n            else if(sc == \'R\' && tc == \'_\'){\n                j++;\n            }\n            else if(tc == \'R\' && i < j && sc == \'_\'){\n                i++;\n            }\n            else if(sc == \'L\' && j < i && tc == \'_\'){\n                j++;\n            }\n            else{\n                return false;\n            }\n            if( i != j){\n                if(i < j){\n                    while(i != j && start.charAt(i) == \'_\'){\n                        i++;\n                    }\n                }\n                else if(j < i){\n                    while(i != j && target.charAt(j) == \'_\'){\n                        j++;\n                    }\n                }\n            }\n            \n        }\n        if( i < j){\n            while( i< j){\n                if(start.charAt(i) != \'_\') return false;\n                i++;\n            }\n        }\n        else{\n            while(j  < i){\n                if(target.charAt(j) != \'_\') return false;\n                j++;\n            }\n\n        }\n        return true;\n        \n    }\n}\n```
['Two Pointers', 'String', 'Java']