Keep track of the position of pieces in your start string | O(N) space and time
The idea is simple:\n\n- Use queue to keep track of the pieces and index occurance in the start string\n- Walk through the target string and when you hit a piec
The idea is simple:\n\n- Use **queue** to keep track of the pieces and index occurance in the **start string**\n- Walk through the **target string** and when you hit a piece:\n\t- Make sure the queue still has pieces\n\t- Pop a piece  from the queue, and make sure they match \n\t- Make sure you can move the piece to the position it occured in the **target string**; by comparing indices \n\t- Finally, only return **True** if no more pieces exist in the queue \n\n\n\n```\ndef canChange(self, start: str, target: str) -> bool:\n\tq, av = collections.deque(), set([\'L\', \'R\'])\n\n\tfor i, c in enumerate(start):\n\t\tif c in av: q.append((i, c))\n\n\tfor i, c in enumerate(target):\n\t\tif c in av:\n\t\t\tif not q: return False\n\n\t\t\tind, char = q.popleft()\n\t\t\tif c != char: return False\n\t\t\telif c == \'R\' and i < ind: return False \n\t\t\telif c == \'L\' and i > ind: return False \n\n\treturn not q \n``` \n\n\n**NOTE**\n\nIt could also be done using a stack, or by keeping track of indices in the **target string** instead of **start string.** \n
['Greedy', 'Queue', 'Python']