Python Beats 100% 1316ms solutions: Mathy
I hope this mathy explanation helps anyone who are interested in finding the minimum number of conditions to check.\nDefine pile[i] to be the numbers N==i (mod 
I hope this mathy explanation helps anyone who are interested in finding the minimum number of conditions to check.\nDefine pile[i] to be the numbers N==i (mod 3), [1,2] means picking 1,2 sequentially for some amout of time.\n1. If there are even number of multiples of 3, \n(1.1) then as long as there are some 1s and 2s, Alice wins by picking the number with the pile with less number, as Bob has to play along the sequence:\n\t1,[1,2],... or 2,[2,1],...\n(1.2) On the other hand, if some piles are missing, Alice always loses as the third multiple pick always gives a lose.\n\n2. If there are odd number of multiples of 3, \n(2.1) If the difference between pile 1 and pile 2 is greater than 2, then alice always wins by again picking the larger pile, i.e. if Alice pick 1, Bob can only pick 0 or 1.\n(2.1.1) If Bob pick 0, then the sequence is 1,0,[1,2],1. Note that there are at least 3 more 1s than 2 so Alice picks 1 after Bob picks the last 2. So Bob loses.\n(2.1.2) if Bob pick 1, then Alice picks 2, the sequence can be 1,[1,2],0,1,[1,2],1 Note that there are at least 3 more 1s than 2. So Alice can force Bob to pick 0 by picking 2s following Bob\'s 1. Then again, in the end, Alice picks 1 after Bob picks the last 2. So Bob loses.\nNote that in this case, the larger pile never runs out so Bob cannot win by taking all stones.\n(2.2) If the difference between two piles are within 2, suppose Alice pick "1" first, then if the remaining 1s are less than or equal to the remaining 2s, Bob picks a 0, and the sequence is 1,0,[1,2],..., and Alice will have no 1 to pick in the end. If there are more 1s than 2s remaining, this means number of 1s is exactly one more than number of 2s as the original difference between two piles are within 2. In this case, Bob picks 1 as long as Alice does not pick 0, i.e.:\n1,[1,2],0,[1,2]\nBecause there are 2 more 1s than 2s originally, in this sequence, 2s will run out first and Alice loses.\n\n\n\n\nCode: \n\n\tdef stoneGameIX(self, stones: List[int]) -> bool:\n\t\tdic = [0,0,0]\n\t\tfor s in stones:\n\t\t\tdic[s%3] +=1           \n\t\tif dic[0] %2 == 0:\n\t\t\treturn (dic[1]*dic[2]!=0)\n\t\telse:\n\t\t\treturn abs(dic[1]-dic[2])> 2\n\n
[]