4
1 2 3 4
for this test case the maximum value picked by piyush can be 7.
because for the first time piyush will pick 4
and if Nitin picks 1 then piyush have the option to pick from 2 and 3 so he can pick 3 which will give total value of 7
4
1 2 3 4
for this test case the maximum value picked by piyush can be 7.
because for the first time piyush will pick 4
and if Nitin picks 1 then piyush have the option to pick from 2 and 3 so he can pick 3 which will give total value of 7
@Jitinkansal it is given that all players will play optimally, then why will Nimit pick 1? Nimit is also trying to maximize his score
ok , now I got it …
will you please the ans for this test case.
10
1 2 3 4 5 6 7 8 9 10
according to me the answer should be 30 but I just want to know if I am evaluating the question correctly.
My code is generating the correct output but I am unable to clear all the testcases.
I am sharing you my code look at it tell me what mistake i am doing and please try not change the code completely.
ohh,sorry…
thank you… but can we solve the problem without DP.
Look at this I did this without DP all thanks to you…
int maxCoin(int a[], int i, int n)
{
if (i > n)
return 0;
int maxp1 = 0, maxp2 = 0;
maxp1 += a[i];
maxp1 += min(maxCoin(a, i + 2, n), maxCoin(a, i + 1, n - 1));
maxp2 += a[n];
maxp2 += min(maxCoin(a, i + 1, n - 1), maxCoin(a, i, n - 2));
return max(maxp1, maxp2);
}