🔥Beats 99.80% 📈 O(n) Easy Beginner Approach
\n# Intuition\nWhoever has the most number of consecutive 3 colors wins.\nSo we need to count the number of moves each person can make.\n\nFor the return value:
![image.png](https://assets.leetcode.com/users/images/15b115b8-ceef-4e57-bcda-00247c8011db_1697638120.9862075.png)\n# Intuition\nWhoever has the most number of consecutive 3 colors wins.\nSo we need to count the number of moves each person can make.\n\nFor the return value: if Alice has more moves than Bob, we `return True`\nelse, we `return False`.\n\n> One might question what happens if number of possible moves of Alice and Bob are _equal_!\n\n> In that case, during the game, Alice and Bob both would have completed their moves and since both have the same number of moves and Since Alice plays first, Bob would have finished the last move. \nThus Alice will have to play and she will be left with no more moves to play.\nThus we `return False` even in that case. \n\n### Thing to note tho :\nA substring `"AAAAAA"` gives Alice a total of 4 Moves and not just 2.\n\n**Move 1**  `"AA _A_ AAA"`\n**Move 2**  `"AA _A_ AA"`\n**Move 3**  `"AA _A_ A"`\n**Move 4**  `"AA _A_ "`\n\nOn contrary to the usual misunderstanding of `A "A" AA "A" A`\n\n# Approach\n> The first approach will be to count the number of occurences of `"AAA"` and `"BBB"` substring in **string colors**. \nBut the `str.count(substring)` will not come handy in this case as it does not count `AAAAAAA` as 4 occurences, but as just 2!! (this is due to the poiunter going beyond the 2nd A i the substring while counting the first occurence of AAA)\n\n**Thing to learn :** \nString functions are just not always handy. They do pull you done soometimes due to internal technicalities. Never rely on them for CP\n\n##### Soo.....\n#### Lets solve it the right way ! \n\nTo find the total number of coonsicutive 3 like colors, we can iterate through the array and find if the next element and its next element are the same. We store the total possible moves in a variable for each color(player).\n\n# Complexity\n- Time complexity: O(n)\n- Space complexity : O(1)\n\n# Code\n```py\nclass Solution:\n    def winnerOfGame(self, colors: str) -> bool:\n        a,b=0,0\n        for i,ii,iii in zip(colors,colors[1:],colors[2:]):\n            if \'A\'==i==ii==iii:a+=1\n            elif \'B\'==i==ii==iii:b+=1\n        return b<a\n\n```\n\n\n> ![image.png](https://assets.leetcode.com/users/images/40b7d747-b5ad-4063-957e-b3b504a05994_1696430447.4877107.png)\n\n> _"catphrase"_\n
['Python3']