Easy cpp solution turn by turn concept


#1
int findmax(vector<int> &A,int low,int high,int turn, vector<vector<int>> &dp)
{
    if(low>high)
    return 0;
    if(dp[low][high]!=-1)
    return dp[low][high];
    if(turn==1)
    return dp[low][high]= max(A[low]+findmax(A,low+1,high,0,dp),A[high]+findmax(A,low,high-1,0,dp));
    else
    return dp[low][high]=min(findmax(A,low+1,high,1,dp),findmax(A,low,high-1,1,dp));
}
int Solution::maxcoin(vector<int> &A) 
{
    vector<vector<int>> dp(A.size(),vector<int> (A.size(),-1));
    return findmax(A,0,A.size()-1,1,dp);
}