Pls find error in this Tushar Roys Solution


#1
int Solution::maxProfit(const vector<int> &A) {
    int m = A.size();
    if(m==0 || m==1) return 0;
    if(m==2) return max(0,A[1]-A[0]);
    int n = 3;
    vector<vector<long long>> dp(n,vector<long long>(m,0));
    for(int i =1;i<n;i++)
    {
        long long maxdiff = -A[0];
        for(int j=1;j<m;j++)
        {
            dp[i][j] = max(dp[i][j-1], maxdiff + A[j]);
            maxdiff = max(maxdiff,dp[i-1][j] -A[j]);
        }
    }
    return dp[n][m-1];
}


#2

return dp[n-1][m-1];