I am failing only one testcase

#include
using namespace std;
long long int max_score(long long int a[], int start, int end ,long long int &sum, long long int &maxScore, bool piyush_turn) {

//base case
if(start == end) {
	
	if(maxScore < sum) 
	maxScore = sum;
	sum = 0;
	return a[start];

}
if(piyush_turn) {
	
	sum += a[start];
	piyush_turn = false;
	max_score(a, start + 1, end, sum, maxScore, piyush_turn);
	sum += a[end];
	piyush_turn = false;
	max_score(a, start, end - 1, sum, maxScore, piyush_turn);
	
	
}
else {
	piyush_turn = true;
	max_score(a, start + 1, end, sum, maxScore, piyush_turn);
	piyush_turn = true;
	max_score(a, start, end - 1, sum, maxScore, piyush_turn);
	

}



return maxScore;

}
int main() {
int n;
cin >> n;
long long int a[n];
for(int i = 0; i < n; i++) {
cin >> a[i];
}
long long int sum = 0;
long long int maxScore = 0;
long long int score;

score = max_score(a, 0, n - 1, sum, maxScore, true);
cout << score;

return 0;

}

this is my code can you please help me why one test is not passed and other are all passed. I am leaving any corner cases

@Sachita3
You are looking for the maximum score through your approach. But we need to look for the maximum sum when both the players are playing optimally, which means is that the score will be lower than the one you are computing because the second player is playing for his/ her benefit too. Please look into the statement closely and refine your approach.

Please revert in case you face any difficulty.

So you mean to say that I need to take in account namit score also, such that it is minimum so that piyush score is maximum. but using recursion I am generating all the cases which I guess cover namit’s low score too

Can you suggest some changes to my code please

@Sachita3
Thats not what I meant. You are choosing that case where Piyush’s score is maximum but you actually need to choose that case which is reached upon by both Piyush and Namit trying to maximize their scores. The recursion state in this case is:

ans = max(arr[s] + min(func(s + 1, e - 1) , func(s + 2, e )) , arr[e] + min(func(s, e - 2), func(s + 1, e - 1))).

Look at the state I have written closely and revert in case you face any difficulty.

I understood your approach but my base case for your approach is when start >= end return 0 but then my code is not passing any test cases. is my base is wrong?

Is my base case is wrong then?

@Sachita3
Can you please send the updated code?
Send it in a cb ide link