[Java/C++/Python] Easy and Concise, 6 lines O(n)
Observation\nCount the frequency of mod3 = 0,1,2.\n\nFirstly, don\'t consider the multiples of 3.\nAlice starts with mod3 = 1, Alice and Bob have to pick 1,1,2,
# **Observation**\nCount the frequency of mod3 = 0,1,2.\n\nFirstly, don\'t consider the multiples of 3.\nAlice starts with `mod3 = 1`, Alice and Bob have to pick 1,1,2,1,2... in order.\nAlice starts with `mod3 = 2`, Alice and Bob have to pick 2,2,1,2,1... in order.\n\nIf Alice starts with 1, then Alice needs 1 and Bob needs 2.\nIf 1 is much more than 2, then Bob is going to lose.\n\nSo if `cnt[0] == 0`, the result can be decided by Alice.\n\nThen, consider the number of multiples of 3.\nIf `cnt[0]` is even,\nBob picks a 3, Alice can always picks one another.\nthe result won\'t be affected.\n\nIf `cnt[0]` is odd,\nthe final result will be reversed,\n(unless the case Bob win for all numbers consumed)\n<br>\n\n#  Missing Case\n[1,1,1,3] gave by @mittal582 and @qingqi_lei,\nwhich can hack some solution.\n<br>\n\n# **Explanation**\nIf `cnt[1] == 0`, Alice needs to start with `mod3 = 2`,\nIf `cnt[2] == 0`, Alice needs to start with `mod3 = 1`.\nAlice can win if `max(cnt[1], cnt[2]) > 2 && cnt[0] % 2 > 0`,\nfor example [1,1,1,3].\n\nIf `cnt[0] % 2 == 0`, easy case for Alice.\nAlice can win in at leasy one of the two options, picking the less one.\n\nOtherwise `cnt[0] % 2 == 1`, this will reverse the result.\nIf `abs(cnt[1] - cnt[2]) > 2`,\nAlice will pick `mod3=2` if `mod3=2` is more\nAlice will pick `mod3=1` if `mod3=1` is more\nIf `abs(cnt[1] - cnt[2]) <= 2`,\nAlice will lose for no number remaining.\n<br>\n\n# **Complexity**\nTime `O(n)`\nSpace `O(1)`\n<br>\n\n**Java**\n```java\n    public boolean stoneGameIX(int[] stones) {\n        int[] cnt = new int[3];\n        for (int a: stones)\n            cnt[a % 3]++;\n        if (Math.min(cnt[1], cnt[2]) == 0)\n            return Math.max(cnt[1], cnt[2]) > 2 && cnt[0] % 2 > 0;\n        return Math.abs(cnt[1] - cnt[2]) > 2 || cnt[0] % 2 == 0;\n    }\n```\n**C++**\n```cpp\n    bool stoneGameIX(vector<int>& stones) {\n        int cnt[3] = {};\n        for (int a: stones)\n            cnt[a % 3]++;\n        if (min(cnt[1], cnt[2]) == 0)\n            return max(cnt[1], cnt[2]) > 2 && cnt[0] % 2 > 0;\n        return abs(cnt[1] - cnt[2]) > 2 || cnt[0] % 2 == 0;\n    }\n```\n**Python**\n```py\n    def stoneGameIX(self, stones):\n        cnt = collections.Counter(a % 3 for a in stones)\n        if min(cnt[1], cnt[2]) == 0:\n            return max(cnt[1], cnt[2]) > 2 and cnt[0] % 2 > 0\n        return abs(cnt[1] - cnt[2]) > 2 or cnt[0] % 2 == 0\n```\n\n# **Solution 2**\n@ye15 help improving the conditions check\n**Java**\n```java\n    public boolean stoneGameIX(int[] stones) {\n        int[] cnt = new int[3];\n        for (int a : stones)\n            cnt[a % 3]++;\n        if (cnt[0] % 2 == 0)\n            return cnt[1] > 0 && cnt[2] > 0;\n        return Math.abs(cnt[1] - cnt[2]) > 2;\n    }\n```\n**C++**\n```cpp\n    bool stoneGameIX(vector<int>& stones) {\n        int cnt[3] = {};\n        for (int a: stones)\n            cnt[a % 3]++;\n        if (cnt[0] % 2 == 0)\n            return cnt[1] > 0 && cnt[2] > 0;\n        return abs(cnt[1] - cnt[2]) > 2;\n    }\n```\n**Python**\n```py\n    def stoneGameIX(self, stones):\n        cnt = collections.Counter(a % 3 for a in stones)\n        if cnt[0] % 2 == 0:\n            return cnt[1] > 0 and cnt[2] > 0\n        return abs(cnt[1] - cnt[2]) > 2\n```
[]