Question not clear

in the example of this question it is said that if piyush takes the coin 4 then nimit will take either coin 1 or 3 and piyush is left with coin 2 so maximum is 6.
but if nimit takes coin 1 after piyush has taken coin 4 then piyush has to choose between coin 2 or 3 and if he choose 3 the sum will be 7 and that will be the maximum not 6 which is mentioned in the example.

Hi @superyash.sri , here both player will play optimally so nimit will choose the coin that will result in less value left for piyush

but in question it is written he will chose either 1 or 3

it means he has choice to choose between 1 and 3 so out of which he will choose thoption which is good for him .
if he had chosen 1 then nimit would have 7 with him that’s why he choose 3 thus piyush getting 6 coins
In the question it is written that both will play optimally
what you mean is the greedy approach you have to think in terms of dynammic programming

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.