GLBians cum here!
Intuition\n1. You can remove an element if both its neighbours have the same colour as the current element, meaning all the A coloured elements between 2 A colo
# Intuition\n1. You can remove an element if both its neighbours have the same colour as the current element, meaning all the A coloured elements between 2 A coloured elements can be removed. (same for B)\n    We use this information to calculate the total number of moves that can be made by Alice and Bob each.\n2. Alice plays first so she needs to make more moves than Bob to win the game.\n\n# Approach\n1. We calculate the total number of As in a contiguous sub-string of As before we hit the first B then add current count(A)-2 to the number of turns Alice can make. We do the same for B this time and we keep repeating till the end of string.\n2. Now, if Alice has a total number of moves more than Bobs, then she wins, else Bob wins.\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n    bool winnerOfGame(string colors) {\n        int n=colors.size();\n        pair<int, int> turns;\n        int cnta{}, cntb{};\n        for(int i{0}; i<n; i++)\n            if(colors[i]==\'A\'){\n                if(cntb!=0){\n                    turns.second+=(cntb>2)?cntb-2:0;\n                    cntb=0;\n                }\n                cnta++;\n            }\n            else{\n                if(cnta!=0){\n                    turns.first+=(cnta>2)?cnta-2:0;\n                    cnta=0;\n                }\n                cntb++;\n            }\n\n        if(cnta!=0)\n            turns.first+=(cnta>2)?cnta-2:0;\n        if(cntb!=0)\n            turns.second+=(cntb>2)?cntb-2:0;\n        if(turns.first>turns.second)  return true;\n        return false;\n    }\n};\n```
['C++']