def stock_profit(prices):
    lowest, best = float('inf'), 0
    for price in prices:
        best = max(best, price - lowest)
        lowest = min(lowest, price)
    return best
