Vivek loves array game

Why getting wrong answer??

import java.util.Scanner;

public class Main {
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int f=0;f<t;f++){
int n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
long sum=0;
for(int i=1;i<n;i++){
sum+=a[i];
}
int k=fun(a,0,a[0],1,sum,a.length-1,new int[n][n]);
System.out.println(k);
}

}
public static int fun(int a[],int i,long sum_l,int j,long sum_r,int lim,int dp[][]){
    if(i>=j||j>lim || i>=a.length || j>=a.length)
        return 0;
    int x=0,y=0;
    if(dp[i][j]!=0)
        return dp[i][j];
    if(sum_l==sum_r){
        x=j-i;
        y=a.length-1-j;
            x=fun(a,0,a[0],1,sum_l-a[0],i,dp)+1;
            y=fun(a,j,a[j],j+1,sum_r-a[j],lim,dp)+1;

        //return x;
        return dp[i][j]=Math.max(x,y);

    }
    else{
        y=0;
        y=fun(a,i+1,sum_l+a[j],j+1,sum_r-a[j],lim,dp);
    }
    return dp[i][j]=Math.max(x,y);
}

}

@Anubhav44044 hey please share your ide link of code so that I can check.

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.