How to approach the problem

All test cases are not passing for my code . Whenever , there is even no of coins left/piyush turn i try to pick that element with which namit will be able to pick coin of less value( or in other sense minimize namit profit ) and when it is namits turn , i try to pick coins of max value .I am getting wrong answer , can someone please guide me on how to approach the problem

Hello @imsharan0105 you have not implemented the code in the right way .
it is mentioned in the code that both the players are playing optimally that why piyush and nimit both play optimally (i.e they will try to win) .
and as the piyush starts first thats why you have to minimise the nimits outcome .

take this example:
let us take the example of the test case .
10
22 50 16 13 8 41 25 43 8 7
in this the piyush chooses number are 7+50+13+41+43
and nimit chooses number are 22+16+8+25+8.
and the output for piyush will be 154.

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.