Skip to content

Instantly share code, notes, and snippets.

View mikevoets's full-sized avatar

Mike Voets mikevoets

View GitHub Profile
@mikevoets
mikevoets / maxprofit.py
Last active August 29, 2015 14:18
Maximum profit of stock prices
def get_max_profit_parker(stock_prices_yesterday):
# make sure we have at least 2 prices
if len(stock_prices_yesterday) < 2:
raise IndexError('Getting a profit requires at least 2 prices')
# we'll greedily update min_price and max_profit, so we initialize
# them to the first price and the first possible profit
min_price = stock_prices_yesterday[0]
max_profit = stock_prices_yesterday[1] - stock_prices_yesterday[0]