code link : https://pastebin.com/9pQGbXz2
what’s wrong in my code
Optimal game starategy-1
Hi @Divya_321
You have forgot to take input of array from user. You are passing a empty array that is why your code is showing 0 as output.
This question can simply be solved by adding numbers at odd places and numbers even places and then returning max of both these as n is even so it will yield correct result.
CODE lINK :https://pastebin.com/KHU1DnbF
why not it is giving wrong ans
4
1 2 3 4
for above input ans should be 7 so why it is given 6, help
See ans should be 6 only for this case.
4
1 2 3 4
because first person first picks up 4 and then second person picks up 3 and then first person picks up 2 making its total to be 6 and second person picks up 1. So its ans should be 6 only.
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.
why we can pick from any side
first can pick 4 in case 2nd picks 1 and than first has an opportunity to pick 3 , so the ans should be 7, tell me what I am unable to understand ,
see in the question it is mentioned that “Both the players play optimally.” so second player will also pick the largest element present among both the ends
CODE LINK : https://pastebin.com/XgfKrMmv
I have modified my code and ran on different sample test cases, but then also it is giving wa please correct it.
Hi @Divya_321
The code that you have shared is passing all the test cases and is giving correct answer.
ok then might it be ide problem at that moment thanks for guidance ,