Optimal game strategy


test casees are not passing

@shampblocks
hello shubham,
ur logic is not correct. here in ur code u are trying greedy appraoch which will not work becuase both palyer are playing optimally (means both will try to maximize their score).

what should be the approach for this?? can you explain with example…

check this ->
image

In this problem opponent will choose maximum element Or can choose any one as we can choose from both end what about opponent

@shampblocks
opponent can choose either from start or from end. it will be maximum or not we cant comment

1 Like

if i want to print my moves how to do it??

simply add cout statement before function call

4
1 2 3 4
for this input anser is 6 and moves are 4 and 2
https://ide.codingblocks.com/s/197697 this is my code where to write cout??

@shampblocks
check this code-> https://ide.codingblocks.com/s/197719

this is not the output i was looking for i want only my anser will come for example for above input output should be 4 and then 2
1 2 3 4 for this input i am picking 4 and then 2 so to get maximum 6 and output should be 4 and then 2

@shampblocks
then it will need some modifications in above code,give it try

btw what i am getting in above code you mentioned?? the remainaing array??

@shampblocks
indices of array element that u picked

what is to_string(i) does? is it a inbuilt func

it converts integer to string

ohk thanks sir…

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.