prices = [7, 1, 5, 3, 6, 4] buy_price = prices[0] max_profit = max(0, prices[1] - buy_price) for price in prices: max_profit = max(0, max_profit, price - buy_price) buy_price = min(buy_price, price) print(max_profit)