PYTHON BEATS 100% WITHOUT USING FOR OR WHILE
Intuition\n\nThe problem doesn\'t require brute-forcing all possible moves to determine whether the target string can be obtained from the start string. Instead
# Intuition\n\nThe problem doesn\'t require brute-forcing all possible moves to determine whether the target string can be obtained from the start string. Instead, we can rely on a few simple rules to verify the transformation:\n\nThe number of L and R characters in both start and target must be the same. This ensures no extra pieces are introduced or removed.\nIf an L piece is in the first position in start, it will never move to the right of its position. Similarly, if an R piece is in the last position, it cannot move to the left of its position.\nIf we remove all _ (blank spaces) from both start and target, the resulting strings must be identical. This is because the relative order of L and R pieces must remain unchanged.\n\n# Approach\n\nFilter the Characters: Remove all _ from start and target and check if the remaining strings are identical. If not, return false.\nTwo-Pointer Validation:\nUse two pointers, one for start and one for target, to verify the movement constraints of L and R.\nEnsure each L in start has a corresponding L in target at a position to its left or the same position (since L can only move left).\nEnsure each R in start has a corresponding R in target at a position to its right or the same position (since R can only move right).\nIf all constraints are satisfied, return true. Otherwise, return false.\n\n# Complexity\n- Time complexity:\n$$O(n)$$ Because of the count phase and the find phase\n\n- Space complexity:\n$$O(1)$$ Because we don\'t use any particular data structure. \n\n# Code\n```python3 []\nclass Solution:\n    def canChange(self, start: str, target: str) -> bool:\n        \n        start_L, start_R = start.count("L"), start.count("R")\n        target_L, target_R = target.count("L"), target.count("R")\n\n        start_without_ = start.replace("_", "")\n        target_without_ = target.replace("_", "")\n\n        max_index_L_start = start.rfind(\'L\')\n        min_index_R_start = start.find(\'R\')\n\n        max_index_L_target = target.rfind(\'L\')\n        min_index_R_target = target.find(\'R\')\n\n        if max_index_L_target > max_index_L_start or min_index_R_target < min_index_R_start:\n            return False\n        \n        if start_without_ != target_without_:\n            return False\n\n        if (start[0] == "L" and target[0] != "L") or (start[-1] == "R" and target[-1] != "R"):\n            return False\n\n        if start_L != target_L or start_R != target_R:\n            return False\n\n\n        return True\n\n        \n        \n```
['String', 'Python3']