Ruby T:O(n), S:O(1), faster than 100%, still exceeding time limit in the contest
The idea is having a pool for remaining \'L\', and remaining \'R\' in the array.\n\nThe pieces cannot be moved if:\n- Encounter any extra \'L\' in start before 
The idea is having a pool for remaining \'L\', and remaining \'R\' in the array.\n\nThe pieces cannot be moved if:\n- Encounter any extra \'L\' in start before we do in target\n- Encounter any extra \'R\' in target before we do in start\n- A start\'s \'L\' waiting for a match, but we encounter a \'R\' in target\n- A target\'s \'R\' waiting for a match, but we encounter a \'L\' in start\n\nNOTE: To Leetcode mods, could we either increase Ruby compiler performance on LeetCode, or increase time for Ruby solutions? Else Ruby devs need to write a much better solutions comparing to other languages in order to be accepted\n\n```\n# @param {String} start\n# @param {String} target\n# @return {Boolean}\ndef can_change(start, target)\n  l_remaining = r_remaining = i = 0\n  n = start.length\n  \n  while i < n\n    if (ti = target[i]) == \'L\'\n      return false if r_remaining > 0\n      l_remaining += 1\n    end\n\n    case start[i]\n    when \'L\'\n      return false if l_remaining < 1\n      l_remaining -= 1\n    when \'R\'\n      return false if l_remaining > 0\n      r_remaining += 1\n    end\n\n    if ti == \'R\'\n      return false if r_remaining < 1\n      r_remaining -= 1\n    end\n\n    i += 1\n  end\n\n  l_remaining == 0 && r_remaining == 0\nend\n```\n\nEDITED: Translated this code to Java, it actually runs in 13ms, faster than 100% and less memory than 100%\n\n```\nclass Solution {\n  public boolean canChange(String start, String target) {\n    int lRemaining = 0, rRemaining = 0;\n    int n = start.length();\n    for (int i = 0; i < n; i++) {\n      char ti = target.charAt(i);\n      char si = start.charAt(i);\n\n      if (ti == \'L\') {\n        if (rRemaining > 0) {\n          return false;\n        }\n        lRemaining++;\n      }\n\n      if (si == \'L\') {\n        if (lRemaining < 1) {\n          return false;\n        }\n        lRemaining--;\n      }\n\n      if (si == \'R\') {\n        if (lRemaining > 0) {\n          return false;\n        }\n        rRemaining++;\n      }\n      \n      if (ti == \'R\') {\n        if (rRemaining < 1) {\n          return false;\n        }\n        rRemaining--;\n      }\n    }\n    return lRemaining == 0 && rRemaining == 0;\n  }\n}\n```
['Java', 'Ruby']