[Java/Python 3] 2 methods w/ brief explanation and analysis.
\nIntuition:\n\nSince Ls and Rs can ONLY move to empty spaces and can NOT swap, the sequences containing all Ls and Rs and only Ls and Rs of start and target mu
\n**Intuition:**\n\nSince `L`s and `R`s can ONLY move to empty spaces and can NOT swap, the sequences containing all `L`s and `R`s and only `L`s and `R`s of `start` and `target` must be same;\nSince `L`s and `R`s can move to left and right only respectively, all positions of `L`s in `start` must be no less than the corresponding ones in `target`, and all positions of `R`s in `start` must be no greater than the corresponding ones in `target`.\n\nBased on the above conclusion we can implement an algorithm as follows:\n\n**Algorithm:**\n\n1. Check if `start` and `target` are same if without `_`\'s;\n2. Check if all positions of `L`\'s in `start` are no less than those in `target`;\n3. Check if all positions of `R`\'s in `start` are no greater than those in `target`;\n4. If all above 3 are yes, return true; otherwise return false.\n\n----\n\n**Method 1: Compare the sequences and the indices of \'L\' and \'R\'.**\n\nCredit to **@Thoyajkiran** for removal of redundant code.\n```java\n    public boolean canChange(String start, String target) {\n        if (!(start.replaceAll("_", "")).equals(target.replaceAll("_", ""))) {\n            return false;\n        }\n        for (int i = 0, j = 0, n = start.length(); i < n && j < n; ++i, ++j) {\n            while (i < n && start.charAt(i) == \'_\') {\n                ++i;\n            }\n            while (j < n && target.charAt(j) == \'_\') {\n                ++j;\n            }\n            if (i < n && j < n && (start.charAt(i) == \'L\' && i < j || target.charAt(j) == \'R\' && i > j)) {\n                return false;\n            }\n        }\n        return true;\n    }\n```\n```python\n    def canChange(self, start: str, target: str) -> bool:\n        if start.replace(\'_\', \'\') != target.replace(\'_\', \'\'):\n            return False\n        i = j = 0\n        n = len(start)\n        while i < n and j < n:\n            while i < n and start[i] == \'_\':\n                i += 1\n            while j < n and target[j] == \'_\':\n                j += 1\n            if i < n and j < n and (start[i] == \'L\' and i < j or start[i] == \'R\' and i > j):\n                return False\n            i += 1\n            j += 1\n        return True\n```\n\n\n**Analysis:**\n\n`replace` and `for loop` contribute `O(n)` time complexity respectively. Each character at most visited twice, hence:\n\nTime & space: `O(n)`, where `n = start.length()`.\n\n----\n\nWe can optimize the space:\n\n```java\n     public boolean canChange(String start, String target) {\n        int i = 0, j = 0, n = start.length();\n        while (i < n || j < n) {\n            while (i < n && start.charAt(i) == \'_\') {\n                ++i;\n            }\n            while (j < n && target.charAt(j) == \'_\') {\n                ++j;\n            }\n            if (i == n || j == n) {\n                return i == j;\n            }\n            if (start.charAt(i) != target.charAt(j) || \n                        start.charAt(i) == \'L\' && i < j ||\n                        start.charAt(i) == \'R\' && i > j) {\n                return false;\n            }\n            ++i;\n            ++j;\n        }\n        return true;\n    }\n```\n```python\n    def canChange(self, start: str, target: str) -> bool:\n        i = j = 0\n        n = len(start)\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            if i == n or j == n:\n                return i == j\n            if start[i] != target[j] or \\\n                    start[i] == \'L\' and i < j or \\\n                    start[i] == \'R\' and i > j:   \n                return False\n            i += 1\n            j += 1\n        return True\n```\n\n**Analysis:**\n\n`for loop` contribute `O(n)` time complexity. Each character  visited once, hence:\n\nTime: `O(n)`, space: `O(1)`, where `n = start.length()`.\n\n----\n\n**Method 2: Count the balance of \'L\'s and \'R\'s.** -- inspired by and hence credit to **@kreakEmp** \n\n```java\n    public boolean canChange(String start, String target) {\n        int balanceL = 0, balanceR = 0;\n        for (int i = 0, n = start.length(); i < n; ++i) {\n            char s = start.charAt(i), t = target.charAt(i);\n            balanceL += t == \'L\' ? 1 : 0;\n            balanceR += s == \'R\' ? 1 : 0;\n            // If both balancers > 0, there must be different \n            // \'L...R...\' subsequence between start and target.\n            if (balanceL * balanceR != 0) {\n                return false;\n            }\n            balanceL -= s == \'L\' ? 1 : 0;\n            balanceR -= t == \'R\' ? 1 : 0;\n            if (balanceL < 0 || balanceR < 0) {\n                return false;\n            }\n        }\n        return balanceL == 0 && balanceR == 0;\n    }\n```\n```python\n    def canChange(self, start: str, target: str) -> bool:\n        balance_L = balance_R = 0\n        for s, t in zip(start, target):\n            balance_L += (t == \'L\')\n            balance_R += (s == \'R\')\n            # If both balancers > 0, there must be different \n            # \'L...R...\'subsequence between start and target.  \n            if balance_L * balance_R != 0:\n                return False\n            balance_L -= (s == \'L\')\n            balance_R -= (t == \'R\')\n            if balance_L < 0 or balance_R < 0:\n                return False\n        return balance_L == balance_R == 0\n```\n\n**Analysis:**\n\n`for loop` contribute `O(n)` time complexity. Each character  visited once, hence:\n\nTime: `O(n)`, space: `O(1)`, where `n = start.length()`.\n
['Java', 'Python3']