Wrong answer in optimal game stategy

My solution fails for the third test case. Can you please tell what condition I’m missing? The variables choice1 and choice2 refer to the choices made by players 1 and 2. I’ve broken the problem into if-else statements depending on whether player one chooses the first element or last and then player two choosing the first element or the last one

#include
using namespace std;
int score = 0;

void gameStrategy(int* a, int n, int start){
//base case
if(start >= n)
return ;

//recrusive case
int choice1 = max(a[start],a[n-1]);
score += choice1;
int choice2;
if(choice1 == a[start]){
    choice2 = max(a[start+1],a[n-1]);
    if(choice2 == a[start+1]){
        gameStrategy(a,n,start+2);
    }
    else{
        gameStrategy(a,n-1,start+1);
    }
}
else{
    choice2 = max(a[start],a[n-2]);
    if(choice2 == a[start]){
        gameStrategy(a,n-1,start+1);
    }
    else{
        gameStrategy(a,n-2,start);
    }
}

}

int main() {
int n;
cin >> n;
int a[n];
for(int i = 0 ; i < n ; i++){
cin >> a[i];
}
gameStrategy(a,n,0);
cout << score;
return 0;
}

hi pranav
your code is not producing correct answer for the below test case
4
8 15 3 7
expected output:
22
your output:
15
correct approach to this question
1.The user chooses the ith coin with value Vi: The opponent either chooses (i+1)th coin or jth coin. The opponent intends to choose the coin which leaves the user with minimum value.
i.e. The user can collect the value Vi + min(F(i+2, j), F(i+1, j-1) )
2. The user chooses the jth coin with value Vj: The opponent either chooses ith coin or (j-1)th coin. The opponent intends to choose the coin which leaves the user with minimum value.
i.e. The user can collect the value Vj + min(F(i+1, j-1), F(i, j-2) )

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.