Optimal Game Strategy -I

I am not getting all test case correct, kindly help me resolve the issue. Here is my code :

@Puneet_Sharma use long for the array

Non change in result after changing int to long. My code:

@Puneet_Sharma
// Consider both the possibilities. You can pick either the first or the last coin.
// Since the opponent plays optimally , we would get the minimum of the remaining coins for each choice.
long pickFirst = arr[i] + Math.min(optimalGame(i + 2, j), optimalGame(i + 1, j - 1));
long pickLast = arr[j] + Math.min(optimalGame(i, j - 2), optimalGame(i + 1, j - 1));

// Pick the max of two as your final result
long ans = Math.max(pickFirst, pickLast);

modify this

After doing the suggested changes in my code, one test case is still showing TLE. Kindly help, here’s my code:

@aa1 arr[i] = s.nextLong(); in line 9 instead of s.nextint();

also replace arr.length with n

this should do it
please mark your doubt as resolved if u are satisfied with the answer