EASY C++ SOLUTION |  2337. Move Pieces to Obtain a String
Intuition\nThe problem involves determining whether it\'s possible to transform a string start into a string target by moving characters \'L\' (left) and \'R\' 
# Intuition\nThe problem involves determining whether it\'s possible to transform a string start into a string target by moving characters \'L\' (left) and \'R\' (right) according to specific rules. The key insight is that:\n1. Character Movement: \'R\' can only move to the right, and \'L\' can only move to the left. Thus, if we encounter an \'R\' in start, it should not encounter an \'L\' in target before it has moved.\n2. Count Matching: The total number of \'L\'s and \'R\'s in both strings must match for a valid transformation.\n3. Order of Movement: The movement should respect the order of characters; for instance, an \'R\' should not jump over an \'L\'.\n\n# Approach\n1. Initialization: Start with two counters, left and right, initialized to zero. These will track the net movements of \'L\'s and \'R\'s respectively.\n2. Iterate through Characters:\n- For each character in both start and target, update the left and right counters based on whether the character is \'L\' or \'R\'.\n- If you encounter an \'R\', increment right. If you encounter an \'L\', decrement left.\n- Simultaneously, do the same for the target string by decrementing or incrementing the respective counters.\n3. Validation:\n- After updating the counters for both strings, check:\n  -  If at any point during the iteration left becomes negative (indicating more left movements than allowed) or if right becomes negative (indicating more right movements than allowed).\n  - If there are any unbalanced movements after processing both strings (i.e., both counters should be zero at the end).\n4. Return Result: If all checks pass, return true; otherwise, return false.\n\n# Complexity\n- Time complexity: O(n), where n is the length of the strings. The algorithm processes each character exactly once.\n- Space complexity: O(1), as we are using a constant amount of space for the counters regardless of input size.4\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    bool canChange(string start, string target) {\n        int left = 0, right = 0;\n\n        for (int i = 0; i < start.size(); i++) {\n            if (start[i] == \'R\') {\n                right++;\n                if (left != 0)\n                    return false;\n            } else if (start[i] == \'L\')\n                left--;\n            if (target[i] == \'R\')\n                right--;\n            else if (target[i] == \'L\') {\n                left++;\n                if (right != 0)\n                    return false;\n            }\n            if (left < 0 || right < 0)\n                return false;\n        }\n        return left == 0 and right == 0;\n    }\n};\n```
['Two Pointers', 'String', 'C++', 'Python3']