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)