Professional Documents
Culture Documents
Assuming that both players are trying to optimize their final value, the optimal strategy for the
game would be as follows:
Alice is going first. Both Alice and Bob will sum up the values of every other number in
alternating sequences, that is, the sum of all odd-positioned values and the sum of all even-
positioned values. Now we consider a few cases:
If there are an even number of values, Alice’s strategy is to simply pick the end that belongs to
the higher summation. This guarantees that Alice can maximize her score. The reason why this
strategy works is because we are assuming that both players are playing optimally, and so if Bob
were to see, based on the optimal strategy, that he couldn’t win the game, he would try as best as
possible to maximize his own score, which means that he must play the same way as Alice and
select the other sequence of alternating values. This shows that Alice is able to maximize her
final score if she simply starts by choosing the value that contributes to the larger of the two
sums; since Bob will always pick from the other sequence to maximize his score, Alice is able to
select all numbers that contribute to the larger sum.
This algorithm runs in O(n) time because our for loop iterates through all the numbers once, and
our while loop adds all the numbers to either player’s total once as well.