How is this a dp question?


#1

It should be under simple arrays


#2
int ans = 0 ;
    int m =  INT_MAX;
    for(auto i:A){
        ans = max(ans,i-m);
        m = min(i,m);
    }
    return ans;

#3

This question should not be in dp.
Its a array question. Even for arrays its a very simple question.


#4

solution using DP
int Solution::maxProfit(const vector &A) {
int n=A.size();
int T10=0;
int T11=INT_MIN;
for(int i=0;i<n;i++){
int T11_old=T11;
T11=max(T11,-A[i]);
T10=max(T10,T11_old+A[i]);
}
return T10;
}