Two Pointer Easy ✅ || C++ ✅✅
"Data structures and algorithms are the building blocks of innovation." \uD83D\uDE80\n\n# Intuition\n Describe your first thoughts on how to solve this problem.
# **"Data structures and algorithms are the building blocks of innovation."** \uD83D\uDE80\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem revolves around validating if the positions of `L` and `R` in `start` can be adjusted to match their positions in `target` under specific movement constraints.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Use two pointers, `i` and `j`, to traverse the `start` and `target` strings, respectively.\n2. Skip all `_` characters in both strings since they can be ignored for alignment purposes.\n3. Check the following conditions:\n   - The current characters in both strings should match (`L` or `R`).\n   - If the character is `L`, ensure `i` (from `start`) is not less than `j` (from `target`), as `L` can only move left.\n   - If the character is `R`, ensure `i` is not greater than `j`, as `R` can only move right.\n4. Continue until both pointers reach the end of their respective strings, ensuring no mismatches occur.\n\n# Complexity\n- **Time complexity:**  \n  $$O(n)$$  \n  Each string is traversed once, where `n` is the length of the strings.\n\n- **Space complexity:**  \n  $$O(1)$$  \n  Only a few variables are used for pointer tracking.\n\n# Code\n```cpp\nclass Solution {\npublic:\n    bool canChange(string start, string target) {\n        int i = 0, j = 0, n = start.size();\n\n        while (i < n || j < n) {\n            while (i < n && start[i] == \'_\') i++;\n            while (j < n && target[j] == \'_\') j++;\n            if (i == n || j == n) break;\n            if (start[i] != target[j]) return false;\n            if (start[i] == \'L\' && i < j) return false;\n            if (start[i] == \'R\' && i > j) return false;\n            i++;\n            j++;\n        }\n        return i == n && j == n;\n    }\n};\n
['Two Pointers', 'String', 'C++']