C++ | O(n) | Comments
C++\n\nclass Solution {\n#define ALICE true\n#define BOB false\npublic:\n    bool stoneGameIX(vector<int>& stones) {\n        int n = stones.size();\n        \n
**C++**\n```\nclass Solution {\n#define ALICE true\n#define BOB false\npublic:\n    bool stoneGameIX(vector<int>& stones) {\n        int n = stones.size();\n        \n        //Counting all the frequency of the remainders\n        int r0 = 0, r1 = 0, r2 = 0;\n        for(int i = 0; i < n ; i++) {\n            if(stones[i] % 3 == 0) r0++;\n            if(stones[i] % 3 == 1) r1++;\n            if(stones[i] % 3 == 2) r2++;\n        }\n        \n        //Condition when their is no remainder of either 1 or 2\n        if(min(r1,r2) == 0) {\n            if(max(r1,r2) > 2 and r0 % 2 > 0) return ALICE;\n            else return BOB;\n        }\n        \n        //when their is more than 2 pairs of remainder 1 and 2\n        if(abs(r1- r2) > 2) return ALICE;\n        \n        //when their is even number of 3 multiples \n        if(r0 % 2 == 0) return ALICE;\n        \n        //In any other case Bob will win always\n        return BOB;\n    }\n};\n```
[]