Transform String by Moving Pieces🔄| Easy Two Pointer | O(N) | Java | C++ | Python
\n# \uD83D\uDD0D Intuition:\nTransform start \u27A1\uFE0F target by sliding:\n\n-     R \uD83D\uDC49 to the right\n-     L \uD83D\uDC48 to the left\n    Skip _ 
\n# \uD83D\uDD0D Intuition:\nTransform start \u27A1\uFE0F target by sliding:\n\n-     R \uD83D\uDC49 to the right\n-     L \uD83D\uDC48 to the left\n    Skip _ (empty spaces) and ensure the rules are followed:\n-     R can\u2019t move left \n-     L can\u2019t move right\n\n---\n-     \uD83D\uDCDD Note/Remember :: Position of \'L\' in target should be less than the position in start \n            similarly, for \'R\' the position in start should be less than the postion in target.\n\n\n\n# \uD83D\uDEE0\uFE0F Approach:\n1\uFE0F\u20E3 Use two pointers to traverse start and target.\n2\uFE0F\u20E3 Skip _ in both strings \uD83C\uDFC3\u200D\u2642\uFE0F.\n3\uFE0F\u20E3 Validate:\n\nCharacters match .\n-     Positions respect movement rules (\u2705 R \uD83D\uDC49, \u2705 L \uD83D\uDC48).\n4\uFE0F\u20E3 Return false if any condition breaks, else true \u2705 when traversal ends.\n\n# Complexity\n- Time complexity:\n-     O(n)\n\n- Space complexity:\n-     O(1)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    bool canChange(string start, string target) {\n        int ind1 = 0 , ind2 = 0 ;\n        while(ind1 < start.size() || ind2 < target.size())\n        {\n            while(ind1 < start.size() && start.at(ind1) == \'_\') ind1++ ;\n            while(ind2 < target.size() && target.at(ind2) == \'_\') ind2++ ;\n\n            if(ind1 == start.size() && ind2 == target.size()) return true ;\n            if(ind1 == start.size() || ind2 == target.size()) return false ;\n\n            if(start.at(ind1) != target.at(ind2) || (start.at(ind1) == \'R\' && ind1 > ind2) || (target.at(ind2) == \'L\' && ind1 < ind2)) return false ;\n\n            ind1++ ;\n            ind2++ ; \n            \n        }\n        return true ;\n    }\n};\n```\n\n```Java []\nclass Solution {\n    public boolean canChange(String start, String target) {\n        int ind1 = 0, ind2 = 0;\n\n        while (ind1 < start.length() || ind2 < target.length()) {\n            while (ind1 < start.length() && start.charAt(ind1) == \'_\') ind1++;\n            while (ind2 < target.length() && target.charAt(ind2) == \'_\') ind2++;\n\n            if (ind1 == start.length() && ind2 == target.length()) return true;\n            if (ind1 == start.length() || ind2 == target.length()) return false;\n\n            if (start.charAt(ind1) != target.charAt(ind2) || \n                (start.charAt(ind1) == \'R\' && ind1 > ind2) || \n                (start.charAt(ind1) == \'L\' && ind1 < ind2)) return false;\n\n            ind1++;\n            ind2++;\n        }\n\n        return true;\n    }\n}\n\n```\n```python []\ndef can_change(start, target):\n    ind1, ind2 = 0, 0\n\n    while ind1 < len(start) or ind2 < len(target):\n        while ind1 < len(start) and start[ind1] == \'_\':\n            ind1 += 1\n        while ind2 < len(target) and target[ind2] == \'_\':\n            ind2 += 1\n\n        if ind1 == len(start) and ind2 == len(target):\n            return True\n        if ind1 == len(start) or ind2 == len(target):\n            return False\n\n        if start[ind1] != target[ind2] or \\\n           (start[ind1] == \'R\' and ind1 > ind2) or \\\n           (start[ind1] == \'L\' and ind1 < ind2):\n            return False\n\n        ind1 += 1\n        ind2 += 1\n\n    return True\n\n```\n```JavaScript []\nvar canChange = function(start, target) {\n    let ind1 = 0, ind2 = 0;\n\n    while (ind1 < start.length || ind2 < target.length) {\n        while (ind1 < start.length && start[ind1] === \'_\') ind1++;\n        while (ind2 < target.length && target[ind2] === \'_\') ind2++;\n\n        if (ind1 === start.length && ind2 === target.length) return true;\n        if (ind1 === start.length || ind2 === target.length) return false;\n\n        if (start[ind1] !== target[ind2] || \n            (start[ind1] === \'R\' && ind1 > ind2) || \n            (start[ind1] === \'L\' && ind1 < ind2)) return false;\n\n        ind1++;\n        ind2++;\n    }\n\n    return true;\n};\n\n```\n```ruby []\ndef can_change(start, target)\n  ind1 = 0\n  ind2 = 0\n\n  while ind1 < start.length || ind2 < target.length\n    ind1 += 1 while ind1 < start.length && start[ind1] == \'_\'\n    ind2 += 1 while ind2 < target.length && target[ind2] == \'_\'\n\n    return true if ind1 == start.length && ind2 == target.length\n    return false if ind1 == start.length || ind2 == target.length\n\n    if start[ind1] != target[ind2] || \n       (start[ind1] == \'R\' && ind1 > ind2) || \n       (start[ind1] == \'L\' && ind1 < ind2) \n      return false\n    end\n\n    ind1 += 1\n    ind2 += 1\n  end\n\n  return true\nend\n\n```\n\n```Go []\nfunc canChange(start string, target string) bool {\n    ind1, ind2 := 0, 0\n\n    for ind1 < len(start) || ind2 < len(target) {\n        for ind1 < len(start) && start[ind1] == \'_\' {\n            ind1++\n        }\n        for ind2 < len(target) && target[ind2] == \'_\' {\n            ind2++\n        }\n\n        if ind1 == len(start) && ind2 == len(target) {\n            return true\n        }\n        if ind1 == len(start) || ind2 == len(target) {\n            return false\n        }\n\n        if start[ind1] != target[ind2] || \n           (start[ind1] == \'R\' && ind1 > ind2) || \n           (start[ind1] == \'L\' && ind1 < ind2) {\n            return false\n        }\n\n        ind1++\n        ind2++\n    }\n\n    return true\n}\n\n```\n\n
['Two Pointers', 'String', 'String Matching', 'C++', 'Java', 'JavaScript']