It works fine for two test cases but gives the wrong answer for the last test case…
plz help don’t know where my code fails
Optimal Game Strategy-I -- All test cases doesn't pass
Where??
where I post my doubt??
Hey Nargis, as you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.
Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.
@Nargis hey nargis you code is giving wrong output for this test case senario
4
8 15 3 7
your output is 15
but expected one 22 so try to optimize it further
In the question it has been describe that both play opimally
for input: 8 15 3 7
first piyush will choose 8
second nitin choose 15(as he also plays optimally)
3rd piyush will choose 7
4th nitin will choose 3
so,piyush has 15 coin in total
@Nargis hey nargis read this carefully
Piyush and Nimit are playing a coin game. They are given n coins with values x1, x2 …. xn where ‘n’ is always even. They take alternate terms. In each turn, a player picks either the first coin or the last coin from the row and removes it from the row. The value of coin is received by that player. Determine the maximum value that piyush can win if he moves first. Both the players play optimally.
as here is written that player picks either the first coin or the last coin from the row and removes it from the row
so in the above test we are picking from last
piyush picks 7
nimit picks 3
piyush picks 15
nimit picks 8
so piyush has 22 coins in total
I will recommending to watch that video again.
which video?
and one ques as you explained nimit is not playing optimally
he has to pick 8?