Table of contents
Best Time to Buy and Sell Stock - DP on Stocks
Problem Link:
Code:
int maximumProfit(vector<int> &prices){
// Write your code here.
int n = prices.size();
int maxi = 0;
int minVal = prices[0];
for(int i=1;i<n;i++){
maxi = max(maxi, prices[i]-minVal);
minVal = min(minVal, prices[i]);
}
return maxi;
}