only one test case is not passing
Plz check my code
the approach you are using is greedy approach
and it will not always give correct output
for this input
26
2396 25316 30085 23080 10269 5711 8306 11536 19092 6816 6305 23649 32583 5585 14193 14859 30265 18026 5528 16126 15212 25591 14789 3900 31395 25529
your code giving output: 230506
but correct output is : 224098
correct recursive code
int OptimalGameStratergy(int *arr,int si,int ei){
// Base Case
if(si==ei)return arr[si];
if(si>ei)return 0;
//Recursive Case
int op1=arr[si]+min(OptimalGameStratergy(arr,si+2,ei),OptimalGameStratergy(arr,si+1,ei-1));
int op2=arr[ei]+min(OptimalGameStratergy(arr,si+1,ei-1),OptimalGameStratergy(arr,si,ei-2));
return max(op1,op2);
}
now optimized this using Top down dp
Reference Code
what are you doing can you please explain me
basic idea of game strategy is you take max when your turns come but in opponent’s turn you will get min
because your opponent also play optimally
there should be a video on your course on optimal game strategy
plz see that video
if it is not in your course
then you can refer this https://www.youtube.com/watch?v=VwjKZQCaTC8
my code is working for 5 4 8 6 which is given in editorial can you give me smaller where it does not work
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.