You are viewing a single comment's thread. Return to all comments →
Just go from end to beginning
long stockmax(vector<int> p) { long ans = 0; int max_num = 0; for(int i = p.size() - 1; i >= 0; i--) { max_num = max(max_num, p[i]); ans += max(0, max_num - p[i]); } return ans; }
Seems like cookies are disabled on this browser, please enable them to open this website
Stock Maximize
You are viewing a single comment's thread. Return to all comments →
Just go from end to beginning