Explanation || Game Theory || Easy O(n)
Intuition\nWe can pick any so order doesn\'t matter .\nAs we only want modulus by 3 take frequency of nums[i]%3.\n\nMake cases :\nif only multiples of 3 are the
# Intuition\nWe can pick any so order doesn\'t matter .\nAs we only want modulus by 3 take frequency of nums[i]%3.\n\nMake cases :\nif only multiples of 3 are there Alice picks first and loses.\n\nif only x%3 == 2 and x%3 == 0 are there then Whoever to pick 3rd x%3 == 2 will lose , if count of x%3 == 2 < 3 then bob will win as array will end with not reaching sum%3 == 0\n\nif only x%3==1 and x%3==0 are there then Whoever to pick 3rd x%3 == 1 will lose , if count of x%3 == 1 < 3 then bob will win as array will end with not reaching sum%3 == 0\n\nif x%3 == 0 , x%3 == 1 and x%3 == 2 are present then it depends if Alice can force a win before end of array .\nThe pattern if Alice chooses 1 and 2 respectively are :\n\n1 1 2 1 2 1 2 1 2 ....\n\n2 2 1 2 1 2 1 2 1 ....\n\nWe will count if among both cases is there a way to make bob lose before end of the array . And we will take all x%3==0 .\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    bool stoneGameIX(vector<int>& stones) {\n        \n        int x=0,y=0,z=0;\n        for(auto&a:stones)\n        {\n            if((a%3)==1)\n                x++;\n            else if(a%3==2)\n                y++;\n            else\n                z++;\n        }\n        if(x==0 && y==0)\n            return false;\n        else if(x==0)\n        {\n            if(y<3)\n                return false;\n            else\n                return (z+3)%2==0;\n        }\n        else if(y==0)\n        {\n            if(x<3)\n                return false;\n            else\n                return (z+3)%2==0;\n        }\n        else\n        {\n\n            int p1 = 1+z+2*min(y-1,x)+(x<y-1);\n            int p2 = 1+z+2*min(y,x-1)+(y<x-1);\n            \n            bool aa=true,bb=true;\n\n            if(p1==x+y+z)\n                aa = false;\n            else\n                aa = (p1+1)%2==0;\n\n            if(p2==x+y+z)\n                bb = false;\n            else\n                bb = (p2+1)%2==0;\n\n            return aa||bb;\n            \n        }\n        return 0;\n    }\n};\n```
['C++']