Python O(n) 6 lines
Turn all stone values to mod 3 to get zeros, ones and twos.\n\nInsights:\n Alice wins if Bob picks up a running sum of 0 mod 3 before either Alice does or stone
Turn all stone values to mod 3 to get zeros, ones and twos.\n\nInsights:\n* Alice wins if Bob picks up a running sum of 0 mod 3 before either Alice does or stones run out.\n* Think of Alice always starting the play at ones or twos(for the most part). Also think of play as only using ones and twos as playsets. \n\t* Without zeros, Bob would follow Alice\'s choice as his first play, then they would start playing in a alternate fashion, i.e. each one choosing the complement of the other\'s last play (1->2 or 2->1). If Bob cannot follow Alice\'s choice as his first play, he loses.\n\t* With even number of zeros, this trend wouldnt be interrupted and Alice can ensure she will start the alternation(i.e. play number 3 of the game) if alternation is possible.\n\t* With odd number of zeros, Alice can force Bob to start the alternation.\n* If alternation is not possible, Alice will win if Bob starts play (by choosing zeros as a stalling mechanism - this is the reason for the "**for the most part** caveat above-)  and there are atleast three of the single play set (ones or twos).\n* If alternation is possible, Alice will win if she starts alternating at the larger of the two sets or Bob starts alternating at the smaller of the two sets. In other words, Alice wins if \n\t* even number of zeros: she starts play at the smaller/either (if equal size) of the two play sets so that she will begin the alternation at what will then be the larger play set\n\t* odd number of zeros: she starts play at the larger of the two sets, forces Bob to start alternation and *to ensure he starts alternating at the smaller of the two play sets, the first two plays must still leave the larger of the two sets larger when alternation begins - this requires a difference of atleast 3*.\n\n**Combining all of this, we get that for Alice to win:\n1. \twith even number of zeros: alternation should be possible\n2. \twith odd number of zeros: difference between play set sizes should be atleast 3**\n\t\n\n\n```\nfrom collections import Counter\nclass Solution(object):\n    def stoneGameIX(self, stones):\n        """\n        :type stones: List[int]\n        :rtype: bool\n        """\n        \n        counts = Counter(stone%3 for stone in stones) \n        \n        if counts[0]%2 == 1 and abs(counts[1]-counts[2]) >= 3:\n            return True\n        \n        if counts[0]%2 == 0 and counts[1] > 0 and counts[2] > 0:\n            return True\n        \n        return False\n        \n
[]