def maxProfit(prices: List[int]) -> int:
    size = len(prices)
    if size == 0:
        return 0
    T = [0 for _ in range(size)]
    i = size - 1
    while i > 0:
        j = i + 1
        while j < size:
            if (prices[j] > prices[i]):
                T[i] = max(T[i], prices[j] - prices[i])
            j += 1
        i += 1
    return max(T)


def maxProfitFaster(prices: List[int]) -> int:
    size = len(prices)
    min_price = float('inf')
    profit = 0
    for p in prices:
        min_price = min(min_price, p)
        profit = max(profit, p - min_price)
    return profit
