Optimal game stratergu-I

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.

isn’t this incorrect?
if piyush picks coin 4
then nimit picks coin 1
then piyush can pick coin 3 making a total of 7.

@Anushka_Jha
hello anushka,
both player are playing optimally .that means both will try to maximize their score.
so in given example
turn 1-> piyush pick 4 then nimit can pick 3
turn 2-> piyush pick 2 then nimit can pick 1
piyush score will be 4+2

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.