✅Easy explanation ever - O(n) solution
Intuition\n Describe your first thoughts on how to solve this problem. \nThe intuition behind this code is to determine the winner of a game played by Alice and
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe intuition behind this code is to determine the winner of a game played by Alice and Bob, where they take alternating turns removing pieces based on specific rules about adjacent colors in the input string.\n\n---\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n The approach involves iterating through the input string to count the consecutive valid moves each player can make and then comparing these counts to determine the winner.\n\n---\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nThe code\'s time complexity is O(n), where n is the length of the input string colors, as it iterates through the entire string once.\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nThe space complexity is O(1) because it uses a constant amount of extra space to store the counts of valid moves for Alice and Bob, regardless of the input string\'s size.\n\n---\n# Do upvote if you like the explanation and solution \u2705\n# Code\n```\nclass Solution {\npublic:\n    bool winnerOfGame(string colors) {\n        int n = colors.length();\n        int aliceWins = 0, bobWins = 0;\n        for (int i = 1; i < n - 1; ++i) {\n            if (colors[i - 1] == \'A\' && colors[i] == \'A\' && colors[i + 1] == \'A\') {\n                aliceWins++;\n            } else if (colors[i - 1] == \'B\' && colors[i] == \'B\' && colors[i + 1] == \'B\') {\n                bobWins++;\n            }\n        }\n        if (aliceWins > bobWins) {\n            return true;\n        }\n        return false;\n    }\n};\n```
['Math', 'String', 'Greedy', 'C', 'Game Theory', 'Python', 'C++', 'Java', 'Python3', 'JavaScript']