Simple C++ solution using only counts. Detailed Explanation
Intuition\n Describe your first thoughts on how to solve this problem. \nHello y\'all. So this problem states that there are 2 people Alice and Bob who are play
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nHello y\'all. So this problem states that there are 2 people $$Alice$$ and $$Bob$$ who are playing a 2 - player turn based game. The idea of the game is to remove a color (represented by $$\'A\'$$ or $$\'B\'$$) from a string of colors . As we know there are basic ground rules for every game and this game has some ground rules as well.\n\n---\n\n- Alice is only allowed to remove a piece colored $$\'A\'$$ if both its neighbors are also colored $$\'A\'$$. She is not allowed to remove pieces that are colored $$\'B\'$$.\n- Bob is only allowed to remove a piece colored $$\'B\'$$ if both its neighbors are also colored $$\'B\'$$. He is not allowed to remove pieces that are colored $$\'A\'$$.\n- Alice and Bob cannot remove pieces from the edge of the line.\n- If a player cannot make a move on their turn, that player loses and the other player wins. \n# Approach\n<!-- Describe your approach to solving the problem. -->\nLet\'s try to understand the logic before we jump into the code. So from the rules we can say that the only way for $$Alice$$ to make a move is that there have to be 3 consecutive $$\'A\'$$ in the string $$colors$$. \n- This means that if in colors there is a substring $$AAA$$ and the $$A$$ in between can be removed to make it $$AA$$ in one turn played by $$Alice$$.\n\nSimilarly the only way for $$Bob$$ to make a move is if there exists 3 consecutive $$\'B\'$$ in $$colors$$.\n\n- This means that if in colors there is a substring $$BBB$$ and the $$B$$ in between can be removed to make it $$BB$$ in one turn played by $$Bob$$.\n\nWe might think that there might be possible cases where one player\'s move might cause a disruption for the other player\'s move but that is not possible here since even after a player\'s turn there are still remaining characters which will not allow for clashes or disruptions to the other player.\n\nSo the simplest logic to this would be to count the number of 3 consecutive $$A$$\'s and $$B$$\'s and see which is greater. If the count is equal then $$Bob$$ wins because he played the last turn and $$Alice$$ does not have a chance to play in the next round.\n\n# Complexity\n- Time complexity:$$O(n)$$ since we are iterating only once to find out the 3 consecutive occurrences of the individual colors ($$A$$ and $$B$$) .\n<!-- Add your time complexity here, e.g. $$O(n)$$ --> \n- Space complexity:$$O(1)$$ since we require only 2 variables to store the count of 3 consective $$A$$\'s and the count of 3 consective $$B$$\'s .\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    bool winnerOfGame(string colors) {\n        int n=colors.size(),counta=0,countb=0; //Declare variables\n        for(int i=1;i<n-1;i++)\n        {\n            if(colors[i-1]==\'A\' && colors[i]==\'A\' && colors[i+1]==\'A\')//Check if there are 3 consecutive A\'s\n            {\n                counta+=1; // If yes add to count\n            }\n            if(colors[i-1]==\'B\' && colors[i]==\'B\' && colors[i+1]==\'B\')//Check if there are 3 consecutive B\'s\n            {\n                countb+=1; //If yes add to count\n            }\n        }\n        return counta>countb; //Compare which count is more and return true or false based on that\n    }\n};\n```\n**IF THIS SOLUTION HELPED YOU PLEASE CONSIDER UPVOTING TYSM :))**
['C++']