🐢Slow and Unintuitive Python Solution | Slower than 95%🐢
\nThe top solution explains how this game is not very complicated and you can determine the winner by counting the number of As and Bs. This is like a more comp
\nThe top solution explains how this game is not very complicated and you can determine the winner by counting the number of As and Bs. This is like a more complicated version of that solution.\uD83D\uDE0E \n\n```\nclass Solution:\n    def winnerOfGame(self, colors: str) -> bool:\n        count = 0 # 0 if Alice\'s turn, 1 if it is Bob\'s turn\n\n        chunks = []\n        i = 0\n        # we start by breaking the input into groups of As and Bs\n        while i < len(colors):\n            new_chunk = [colors[i]]\n            while i < len(colors) - 1 and colors[i + 1] == colors[i]:\n                i += 1\n                new_chunk.append(colors[i])\n\n            if new_chunk:\n                chunks.append(new_chunk)\n            i += 1\n\n        # We filter the chunks into valid chunks, which contain\n        # three or more of a color\n        alice_valid_chunks = [chunk for chunk in chunks if chunk[0] == "A" and len(chunk) > 2]\n        bob_valid_chunks = [chunk for chunk in chunks if chunk[0] == "B" and len(chunk) > 2]\n        \n        # we simulate the game.\n        for i in range(len(colors)):\n            if count == 0: # Alice\'s turn\n                if alice_valid_chunks and len(alice_valid_chunks[-1]) > 2:\n                    alice_valid_chunks[-1].pop()\n                    if len(alice_valid_chunks[-1]) < 3:\n                        alice_valid_chunks.pop()\n                else: # she has run out of moves\n                    return False\n            else: # Bob\'s turn\n                if bob_valid_chunks and len(bob_valid_chunks[-1]) > 2:\n                    bob_valid_chunks[-1].pop()\n                    if len(bob_valid_chunks[-1]) < 3:\n                        bob_valid_chunks.pop()\n                else: # he has run out of moves\n                    return True\n            \n            count ^= 1\n            \n        return False\n```
['Python3']