Skip to content

Instantly share code, notes, and snippets.

@nerohoop
Created July 22, 2017 10:25
Show Gist options
  • Save nerohoop/0f2155f665a4a95291c5bc83d3ddc544 to your computer and use it in GitHub Desktop.
Save nerohoop/0f2155f665a4a95291c5bc83d3ddc544 to your computer and use it in GitHub Desktop.
int maxRight[size-1];
maxRight[size-2] = price[size-1];
for(int i=size-3; i>=0; i--) {
maxRight[i] = MAX(price[i+1], maxRight[i+1]);
}
long long profit = 0;
for(int i=0; i<size-1; i++) {
if(maxRight[i] > price[i]) {
profit += maxRight[i] - price[i];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment