this probelm code I have checked it many times, plz help
Why no output or garbage value is coming
Hello @Akshay123,
It the logic you have applied to solve this question.
It is a very tricky question.
Let’s understand this:
let the index at which the leftmost coin is available be l (initially 0)
and the index at which the rightmost coin is available be r (initially n-1)
if piyush chooses l
then in the next pick he will have two possible choices:
(l-1,r-1): the opponent has selected the rightmost coin
(l-2,r): the opponent has selected the leftmost coin.
sum= arr[l]+min(fun(l-1,r-1),fun(l-2,r))
opponent will choose something that will cause piyush to have minimum sum.
if piyush chooses r
then in the next pick he will have two possible choices:
(l-1,r-1): the opponent has selected the leftmost coin
(l,r-2): the opponent has selected the rightmost coin.
sum= arr[r]+min(fun(l-1,r-1),fun(l,r-2))
opponent will choose something that will cause piyush to have minimum sum.
Hope, this would help.
Give a like if you are satisfied.
Hello @Akshay123,
There were many mistakes in your code:
Hope, this would help.
Give a like if you are satisfied.
THANKS MAN FOR SOLVING THIS, HATS OFF
i hope there is TLE in test case 2 becoz of no DP solution
yes I will Thanks, also can u help me in my doubt of recusion - dictionary orer( smaller), I don’t know why only test case 0 is failing rest all are getting AC, here is the code https://ide.codingblocks.com/s/212888
I have also asked my doubt in that section also since night, but getting no response, plz help
Sure @Akshay123,
But please post a separate doubt for this question and mark this one as resolved.
Someone must have acknowledged your doubt as i cannot see it on the portal.
He will respond to you soon.
ok , i have already marked it resolved.