O(n) time O(1) space solution greedy
Intuition\n Describe your first thoughts on how to solve this problem. \n\nAfter seeing the question the first thing that comes to mind is number of moves for a
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nAfter seeing the question the first thing that comes to mind is number of moves for alice should be greater than number of moves Bob for ALice to win. Hence we need to find number of moves of both the players.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nNow since we can see 3 A can make 1 move and after that if there are extra A\'s then it will combine with the 2 A\'s that were remaining. Hence that should also be counted as 1 move. \nSimilarly for Bob we will find moves. \n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\nTime Complexity - O(n) for traversing the string.\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\nSpace Complexity - O(1)\n\n# Code\n```\nclass Solution {\npublic:\n    bool winnerOfGame(string colors) {\n        int countA=0,countB=0,movesA=0,movesB=0;\n\n        for(int i=0;i<colors.length();i++){\n            if(colors[i]==\'A\'){\n                countA++;\n                if(countA>=3){\n                    movesA++;\n                }\n                countB=0;\n            }\n            if(colors[i]==\'B\'){\n                countB++;\n                if(countB>=3){\n                    movesB++;\n                }\n                countA=0;\n            }\n        }\n        return movesA>movesB;\n    }\n};\n```
['Math', 'Greedy', 'C++']