OPTIMAL GAME STRATEGY-I

sir,why my code is failing all the test cases.
they have asked the maximum profit that piyush can make if both of them take alternate terms.
then according to me ,piyush would win maximum profit,if we sort the array and piyush takes the coin from the end while the other guy from the beginning.and so in this way piyush only gets the maximum value coins.

or tell me if i have interpreted the question wrongly!

We cannot sort the array as it can change the ordering.
Because It is given in the question " In each turn, a player picks either the first coin or the last coin from the row and removes it from the row. "

Refer this for the approach Doubt in understanding the question