sir, how can i implement the alternate turn for ‘‘nimit’’. here is my code -> https://ide.codingblocks.com/s/458942
Sir, i'm unable to implement the another part of code
hello @chandreshmaurya
you can pass a bool variable to indicate the turn (0 for nimit, 1 piyush).
after the turn is complete and when u make next call then flip the turn value (ie if 0 then 1 ,if 1 then 0).
also greedy approach will not work here. try to think of another approach or just try to simulate the situation using recusion.
sir, i got the concept:- max((a[s] + min((s+2 —>e), (s+1—>e-1))), (a[e] + min((s+1—>e-1), (s—>e-2))))
but, unable to implement that
check this->
ll optimalGame(ll i,ll j){
if(i > j){
return 0;
}
// Consider both the possibilities. You can pick either the first or the last coin.
// Since the opponent plays optimally , we would get the minimum of the remaining coins for each choice.
ll pickFirst = coins[i] + min( optimalGame(i+2,j) , optimalGame(i+1,j-1) ) ;
ll pickLast = coins[j] + min( optimalGame(i,j-2) , optimalGame(i+1,j-1) ) ;
// Pick the max of two as your final result
ll ans = max(pickFirst,pickLast);
return ans;
}
please help me to implement this apporoach.
…
check my last response
yes sir, i,m going through that
sir, i code it with the help of u and got correct answer. but, i have a doubt in the line of 7, what does the mean of “return 0;” if (s>e). here is my code --> https://ide.codingblocks.com/s/459019
it is the case when we have no element left in the array and simply in that case max score possible is 0, that is why we are returning 0
ok sir, i got it. thank you sir 
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.