I don't know why I'm getting wrong answer though I get the right output in my IDE

code-https://ide.codingblocks.com/s/326557

I sorted the code so that the person always chooses the last number every time.
So that’s why I reduce i by 2 every time because our player will choose every second number from the end.

you cant sort the array . you have to use the same array then only they can play optimally
you can watch the video in dp section of your course. they give a very fine explanation


I updated the code to work without sorting but still passes some of the test cases not all.
I don’t know dp yet so trying to do this with recursion

please reply, its not accepting it

@amanb25 your logic is incorrect .
please see this code for reference.

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.