First test case is not passing
One test case is not passing
@tusharnitharwal,
That’s because you trying to greedily choose the terminal elements, rather you have to recursively check and choose which is optimum.
No, i have done it recursively
I have done it recursively only. Please help me out in finding the error
@tusharnitharwal,
You have not,
if(a[i+1] > a[j])
By writing this you restricted recursions direction just on the basis of greedy idea that you would definitely pick the larger of two, which is wrong.
This line is not for the first player’s selection. It is for the opponent’s selection.
Can you just please tell me the test case for which the code is not running?
@tusharnitharwal,
It does not matter who’s turn it is, even the opponent is playing optimally, not greedily.