Optimal Game strategy

I am not getting this question.
Piyush and Nimit are playing a coin game. They are given n coins with values x1, x2 …. xn where ‘n’ is always even.
They take alternate terms. In each turn, a player picks either the first coin or the last coin from the row and
removes it from the row. The value of coin is received by that player. Determine the maximum value that Piyush can
win with if he moves first. Both the players play optimally.
Sample Input
4
1 2 3 4
Sample Output
6
Explanation
Piyush will pick the coin 4. Then Nimit can pick either 1 or 3. In both the cases piyush picks coin 2 and wins with
a total of 6.

if Piyush picks 4 in 1st chance , that leaves the array {1,2,3}
and now if Nimit can pick from 1/3 and if he picks 1 that leaves the array {2,3} and now piyush can pick three and that makes the total 7 so how is the maximum possible answer 6?
please explain the question.

you can refer to this discussion i have previously explained

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.