why my one test case is sgetting failed
Optimal game stategy i
Hey @lovely check for this test case:
10
22 50 16 13 8 41 25 43 8 7
Expected output is: 154
Yours is giving is: 112
The issue is with your recursive call, it’s partially correct. You have to choose in such a way that you leave minimum values for your opponent which are in the min(argument1, argument2) and whatever the maximum is , it should be choosen by you.
if (i>j) return 0; // this should be your base case
int op1 = a[i] + min(f(a, i + 2, j), f(a, i + 1, j - 1));
int op2 = a[j] + min(f(a, i + 1, j - 1), f(a, i, j - 2));
return max(op1, op2);
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.