Does Piyush’s opponent also chooses the coin having the maximum value or he chooses any coin?
Question Not Clear
Hello @Doctor_Insult,
You have raised the most appropriate doubt regarding this question.
Answer:
- He might not choose the maximum coin always.
- He will surely not choose any choice.
What would he choose than?
He will choose a coin so that Piyush will get the minimum value.
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.
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.