Optimal Game Strategy-II

help me with code

@Legendankit just think this way:

  1. Base case is when no coin is left ===> i>j, simply return 0
  2. You can choose ith or jth bottle for now!
  3. If its your turn return max(a[i]+solve(i+1,j),a[j]+solve(i,j-1)) else return min(solve(i+1,j),solve(i,j-1)) as your opponent also plays optimally.
  4. Just think a bit how to calculate whose turn is it using i and j!
  5. memoize!!

thanks but Still I’m facing the issue

Well in that case I suggest you unlock editorial!

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.