Only one test case has failed to pass

Now one test case is not passing help me with the test case
Here is my Code of the function-
"public static int count(int arr[],int si,int ei,int p){
if(si>=ei){
return 0;
}

 if(p==1){
    
		 int f=arr[si]+count(arr,si+1,ei,0);
		 int s=arr[ei]+count(arr,si,ei-1,0);
		 return Math.max(f,s);
	
		 
	 
 }else{
     if(arr[si]>arr[ei]){
		 return count(arr,si+1,ei,1);
	 }else{
		 return count(arr,si,ei-1,1);
	 }
 }

}"

@guptadev354 your code passes only one test case.

refer to this

import java.util.Scanner;

public class Main {

static long[] arr;

public static long optimalGame(int i, int j) {
    if (i > j) {
        return 0;
    }
    //  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);

    return ans;
}

public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    arr = new long[n];
    for (int i = 0; i < n; i++) {
        arr[i] = sc.nextLong();
    }

    System.out.println(optimalGame(0, n - 1));

}

}