[Java] Two Pointer One Pass O(n) with Explanation
We have 3 cases to handle:\n1. if Xs are removed, the two strings should be identical.\n2. L cannot go to right.\n3. R cannot go to left.\n\nBased on that we ca
We have 3 cases to handle:\n1. if Xs are removed, the two strings should be identical.\n2. L cannot go to right.\n3. R cannot go to left.\n\nBased on that we can use two pointers and check Rs and Ls positions.\n\n```\npublic boolean canTransform(String start, String end) {\n    char[] s = start.toCharArray();\n    char[] e = end.toCharArray();\n\n    int i = 0, j = 0;\n    while(i < s.length && j < e.length){\n      if(s[i] == \'X\'){\n        i++;\n      }else if(e[j] == \'X\'){\n        j++;\n      }else{\n        if(s[i] != e[j] || s[i] == \'R\' && j < i || s[i] == \'L\' && j > i) return false;\n        i++;\n        j++;\n      }\n    }\n\n    while(i < s.length){\n      if(s[i++] != \'X\') return false;\n    }\n\n    while(j < e.length){\n      if(e[j++] != \'X\') return false;\n    }\n\n    return true;\n  }\n
['Two Pointers']