🔥BEATS 💯 % 🎯 |✨SUPER EASY BEGINNERS 👏
\n\n---\n\nHere\u2019s the detailed explanation and solution for the problem of checking whether start can be transformed into target by moving \'L\' to the lef
![image.png](https://assets.leetcode.com/users/images/40ee1633-9c44-40fd-a37b-f5c9ec1efd40_1733383370.5600271.png)\n\n---\n\nHere\u2019s the detailed explanation and solution for the problem of checking whether `start` can be transformed into `target` by moving \'L\' to the left and \'R\' to the right, skipping the blanks represented by `_`.\n\n---\n\n# Intuition\nThe problem can be visualized as aligning two strings (`start` and `target`) by respecting movement constraints:\n1. \'L\' can only move to the left (reducing its index).\n2. \'R\' can only move to the right (increasing its index).\n3. Blank spaces `_` are ignored, and the relative order of characters must be maintained.\n\nUsing two pointers allows efficient traversal while skipping blanks and verifying the transformation.\n\n---\n\n# Approach\n1. Initialize two pointers `i` and `j` for `start` and `target`, respectively.\n2. Skip all `_` in both strings until a non-blank character is encountered or the pointer reaches the end of the string.\n3. Check:\n   - If characters at `start[i]` and `target[j]` mismatch, the transformation isn\'t possible.\n   - If the character is `L` and its position in `start` is greater than its position in `target`, return `false` (it can\'t move right).\n   - If the character is `R` and its position in `start` is less than its position in `target`, return `false` (it can\'t move left).\n4. Repeat until both pointers reach the end. If they do, return `true`.\n\n---\n\n# Complexity\n- **Time complexity:**  \n  $$O(n)$$ where \\(n\\) is the length of the strings. Each character is processed once.\n  \n- **Space complexity:**  \n  $$O(1)$$ since we only use two pointers for traversal.\n\n---\n\n\n```dart []\nclass Solution {\n  bool canChange(String start, String target) {\n    int n = start.length;\n    int i = 0, j = 0;\n\n    while (i < n || j < n) {\n      // Skip blanks (\'_\') in `start`\n      while (i < n && start[i] == \'_\') i++;\n      // Skip blanks (\'_\') in `target`\n      while (j < n && target[j] == \'_\') j++;\n\n      // If one pointer reaches the end but the other doesn\'t, return false\n      if (i == n || j == n) return i == n && j == n;\n\n      // Compare the pieces at the current positions\n      if (start[i] != target[j]) return false;\n\n      // Movement constraints:\n      if (start[i] == \'L\' && i < j) return false; // \'L\' can\'t move right\n      if (start[i] == \'R\' && i > j) return false; // \'R\' can\'t move left\n\n      // Move both pointers\n      i++;\n      j++;\n    }\n\n    return true;\n  }\n}\n\n\n```\n\n```c []\n#include <stdbool.h>\n#include <string.h>\n\nbool canChange(char* start, char* target) {\n    int n = strlen(start);\n    int i = 0, j = 0;\n\n    while (i < n || j < n) {\n        while (i < n && start[i] == \'_\') i++;\n        while (j < n && target[j] == \'_\') j++;\n\n        if (i == n || j == n) return i == n && j == n;\n        if (start[i] != target[j]) return false;\n\n        if (start[i] == \'L\' && i < j) return false;\n        if (start[i] == \'R\' && i > j) return false;\n\n        i++;\n        j++;\n    }\n\n    return true;\n}\n```\n```cpp []\nclass Solution {\npublic:\n    bool canChange(string start, string target) {\n        int n = start.size();\n        int i = 0, j = 0;\n\n        while (i < n || j < n) {\n            while (i < n && start[i] == \'_\') i++;\n            while (j < n && target[j] == \'_\') j++;\n\n            if (i == n || j == n) return i == n && j == n;\n            if (start[i] != target[j]) return false;\n\n            if (start[i] == \'L\' && i < j) return false;\n            if (start[i] == \'R\' && i > j) return false;\n\n            i++;\n            j++;\n        }\n\n        return true;\n    }\n};\n```\n```java []\nclass Solution {\n    public boolean canChange(String start, String target) {\n        int n = start.length();\n        int i = 0, j = 0;\n\n        while (i < n || j < n) {\n            while (i < n && start.charAt(i) == \'_\') i++;\n            while (j < n && target.charAt(j) == \'_\') j++;\n\n            if (i == n || j == n) return i == n && j == n;\n            if (start.charAt(i) != target.charAt(j)) return false;\n\n            if (start.charAt(i) == \'L\' && i < j) return false;\n            if (start.charAt(i) == \'R\' && i > j) return false;\n\n            i++;\n            j++;\n        }\n\n        return true;\n    }\n}\n```\n```go []\nfunc canChange(start string, target string) bool {\n    n := len(start)\n    i, j := 0, 0\n\n    for i < n || j < n {\n        for i < n && start[i] == \'_\' {\n            i++\n        }\n        for j < n && target[j] == \'_\' {\n            j++\n        }\n\n        if i == n || j == n {\n            return i == n && j == n\n        }\n        if start[i] != target[j] {\n            return false\n        }\n\n        if start[i] == \'L\' && i < j {\n            return false\n        }\n        if start[i] == \'R\' && i > j {\n            return false\n        }\n\n        i++\n        j++\n    }\n\n    return true\n}\n```\n```python []\nclass Solution:\n    def canChange(self, start: str, target: str) -> bool:\n        n = len(start)\n        i, j = 0, 0\n\n        while i < n or j < n:\n            while i < n and start[i] == \'_\':\n                i += 1\n            while j < n and target[j] == \'_\':\n                j += 1\n\n            if i == n or j == n:\n                return i == n and j == n\n            if start[i] != target[j]:\n                return False\n\n            if start[i] == \'L\' and i < j:\n                return False\n            if start[i] == \'R\' and i > j:\n                return False\n\n            i += 1\n            j += 1\n\n        return True\n```\n```javascript []\nvar canChange = function(start, target) {\n    let n = start.length, i = 0, j = 0;\n\n    while (i < n || j < n) {\n        while (i < n && start[i] === \'_\') i++;\n        while (j < n && target[j] === \'_\') j++;\n\n        if (i === n || j === n) return i === n && j === n;\n        if (start[i] !== target[j]) return false;\n\n        if (start[i] === \'L\' && i < j) return false;\n        if (start[i] === \'R\' && i > j) return false;\n\n        i++;\n        j++;\n    }\n\n    return true;\n};\n```\n\n---\n\n![image.png](https://assets.leetcode.com/users/images/d81a7cee-fa73-41a2-82dc-65bf475d960c_1722267693.3902693.png) {:style=\'width:250px\'}
['Two Pointers', 'String', 'C', 'C++', 'Java', 'Go', 'Python3', 'JavaScript', 'Dart']