Track minimum price and maximum profit in a single pass.
function maxProfit(prices): minPrice = infinity maxProfit = 0 for price in prices: minPrice = min(minPrice, price) profit = price - minPrice maxProfit = max(maxProfit, profit) return maxProfit
time, space.