Skip to content

Instantly share code, notes, and snippets.

@Dpalazzari
Last active May 11, 2017 19:53
Show Gist options
  • Save Dpalazzari/3cbb2f16a27759ceb662f5b2b7a0dc1c to your computer and use it in GitHub Desktop.
Save Dpalazzari/3cbb2f16a27759ceb662f5b2b7a0dc1c to your computer and use it in GitHub Desktop.

We’re going to analyze yesterday’s stock prices to determine what our maximum profit would have been had we bought and sold stock at a certain point in the day. To get started, assume the data is an array of integer values to write your algorithm and then I’ll give you additional data points once your algorithm is finished to determine how correct your algorithm is.

First data point: Gains and losses throughout the day:

stock_prices_yesterday = [10, 7, 5, 8, 11, 9];
# return 6 (buying for $5 and selling for $11, making a $6 profit)

Second data point: Only losses throughout the day:

stock_prices_yesterday = [15, 13, 9, 7, 6, 4]
# return -1  (bought at 7, sold at 6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment