GATE Computer ScienceVery hardGATE CS (PYQ pattern)

Two players alternately take a coin from either end of the row 20, 9, 12, 17, 1, 15, 8, 2 (the total is 84) and both play optimally to maximise their own sum. What is the largest total that the first player can guarantee?

  1. A. 54
  2. B. 49
  3. C. 52
  4. D. 56

Correct answer: A. 54

Let f(i, j) = max(a[i] − f(i + 1, j), a[j] − f(i, j − 1)) be the best margin; f = 24, so the first player gets (84 + 24)/2 = 54. The greedy rule (always take the larger end) gives only 49.

More Algorithms questions

Exams that ask this topic