In this question…is coins are arranged in increasing order always…mean do i get the input in increasing order always or randomly?
Please answer this
No.it is not necessary that coins are arranged in increasing order.
Ok…so what will will i write in my code to find what other person picks firast or last i cant get his inpur so how will i do…and can i solve this q without dp?
Optimal Game Strategy 1 can be solved using pure recursion. For Optimal Game Strategy 2, you have to use DP.
Follow this
At each instance we would need to consider two possibilities that we can pick the first as well as the last element of the remaining array. Both these possibilities give rise to two more possibilities depending on the other player. Since the second player plays optimally and try to minimise our score. So overall we have two possibilities at each instance.
For the first possibility , where we could pick the first element , the other player will pick the next element from the side that would minimise our total score.
Similarly , for the second possibility , where we can pick the last element , the other player would still pick the next element from the side that would minimise our total score.
We entertain both these cases and take the maximum result of the two and return that result.
We take two pointer variables , say ‘i’ and ‘j’ which each represent the starting and the ending point of the remaining array currently in consideration. We work till the two pointers cross each othe
Code for reference: https://ide.codingblocks.com/s/286976
https://ide.codingblocks.com/s/287135…can i use this kind of approach…although i am not able to implement it properly…but trying to implement with other logic than yours…plz help