Unable to pass the 6th test case, please help.
Optimal Game Strategy
@Yuvraj_Luhach,
You were not considering the optimal solution.
Calculate all the possible solutions and taking their max at each recursive step as both of them play optically.
Let’s say you and I are playing this game.
I will first choose greater of a[i] or a[j]
then you will choose in such a way that any future move by me gains me minimum profit so bascially you will allow me to choose:
condition1 = a[i] + min( func(i+2 , j ) , func ( i+1 , j-1))
condition2 = a[j] + min( func(i+1 , j -1) , func(i, j-2))
now since you need to play with max value
We will do max( condition1 , condition2)
https://ide.codingblocks.com/s/195815 here is the corrected solution
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.