Skip to content

Instantly share code, notes, and snippets.

@SmellyFish
Created March 14, 2016 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SmellyFish/93b22f52baaebf3f0628 to your computer and use it in GitHub Desktop.
Save SmellyFish/93b22f52baaebf3f0628 to your computer and use it in GitHub Desktop.
Prasad stock solution
// given an array of prices, determine the largest profit that can be made
[310, 315, 275, 295, 260, 270, 290, 230, 255, 250]
private int findMaxProfit(int[] stockPrices) {
int maxProfit = 0;
// TODO: Implement later
validateStockPrices();
for (for int i = 0; i < stockPrices.length - 2; i++) {
for (int j = i + 1; j < stockPrices.length - 1; j++) {
int profit = stockPrices[j] - stockPrices[i];
if (profit > maxProfit) {
maxProfit = profit;
}
}
}
return maxProfit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment