Sliding window | Single Pass | O(1) space
\n# Approach\nUsing sliding window of size if size>2 then add size-2 in the index of Alice/freqa[0] or Bob/freqb[1] else add 0 our window is not useful\n\n\n# C
\n# Approach\nUsing sliding window of `size` if size>2 then add `size-2` in the index of `Alice`/`freqa[0]` or `Bob`/`freqb[1]` else add `0` our window is not useful\n\n\n# Complexity\n- Time complexity:\n`O(n)`\n\n- Space complexity:\n`O(1)`\n\n# Code\n```\nclass Solution {\npublic:\n    bool winnerOfGame(string colors) {\n        // try - sliding window\n        int left = 0;\n        int right = 0;\n        vector<int> freqa(2,0);\n\n\n        while(right<colors.size()){\n            int size = 0;\n            while(colors[right]==colors[left]){\n                size+=1;\n                right+=1;\n            }\n\n            freqa[colors[left]-\'A\']+=size>2?size-2:0;\n            left=right;\n        }\n        return freqa[0]>freqa[1];\n    }\n};\n```
['String', 'Sliding Window', 'C++']