Wrong answer error

I am facing wrong answer error. I have run the code for a number of testcases but I am still facing wrong answers.
Kindly have a look at the code.

NEW APPROACH - https://ide.codingblocks.com/s/186784

Earlier this question was a part of RECURSION and I did that in HACKER BLOCKS but as I am now re-submitting the same solution , It’s giving wrong answer error on both the platforms.

OLD APPROACH - https://ide.codingblocks.com/s/186786

@mananaroramail,
I have corrected your code and commented the new code. https://ide.codingblocks.com/s/186789

1 Like

Ok , What you did was calculating all the possible solutions and taking their max at each recursive step as both of them play optically.
So in this question we can’t see the inner numbers. But what I did was - I calculated the result according to the max of the numbers at – ci , ci + 1 , li , li -1 and then played the next move.
What was wrong with that approach ?

@mananaroramail,

Let’s say you and I are playing this game.
I will first choose greater of a[i] or a[j]
then you will choose in such a way that any future move by me gains me minimum profit so bascially you will allow me to choose:

condition1 = a[i] + min( func(i+2 , j ) , func ( i+1 , j-1))
condition2 = a[j] + min( func(i+1 , j -1) , func(i, j-2))

now since you need to play with max value
We will do max( condition1 , condition2)

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.