Why is it wrong?

include <bits/stdc++.h>

using namespace std;

define ll long long int

ll find(ll a[],ll s,ll e){

if(s==e)

	return a[s];

if(s>e)

	return 0;

if(s+1 == e)

	return max(a[s],a[e]);

return max(a[s]+min(find(a,s+1,e-

2),find(a,s+2,e)),a[e]+min(find(a,s+1,e-1),find(a,s,e-2)));

}

int main(){

ll i,n;

cin>>n;

ll a[n];

for(i=0;i<n;i++)

	cin>>a[i];

cout<<find(a,0,n-1)<<endl;

return 0;

}

hello @Mr_robot
is it showing tle?

nope, just wrong answer!

I got it right this time, I might have messed it up in the return statement, i guess!!

this worked for me-

#include <bits/stdc++.h>
using namespace std;
#define ll long long int


ll score(ll a[],ll s,ll e){
	ll val1 = 0,val2 = 0;
	if(s>e)
		return 0;
	if(s==e)
		return a[s];
	if(s+1==e)
		return max(a[s],a[e]);
	val1 = a[s] + min(score(a,s+1,e-1),score(a,s+2,e));
	val2 = a[e] + min(score(a,s,e-2),score(a,s+1,e-1));
	return max(val1,val2);
}

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

THANKS!! :smiley:

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.