class Solution(object):
    # At most one transaction
    def get_max_profit(self, prices):
        max_profit = 0
        if not prices:
            return max_profit
        buy = prices[0]

        for i in range(1, len(prices)):
            price = prices[i]
            buy = min(price, buy)
            max_profit = max(max_profit, price - buy)
    
        return max_profit

    # At most one transaction
    def get_max_profit3(self, prices):
        buy = float('inf')
        profit = 0
        for price in prices:
            buy = min(price, buy)
            profit = max(profit, price - buy)
        
        return profit
    
    # At most one transaction
    def get_max_profit2(self, prices):
        currMax = 0
        maxSoFar = 0

        for i in range(1, len(prices)):
            currMax = max(0, currMax + prices[i] - prices[i - 1])
            maxSoFar = max(currMax, maxSoFar)
        
        return maxSoFar
    
    # unlimited transactions
    def get_max_profit4(self, prices):
        return sum([max(prices[i] - prices[i - 1], 0) for i in range(1, len(prices))])


solution = Solution()
print(solution.get_max_profit([7, 1, 5, 3, 6, 4]))
print(solution.get_max_profit([7, 6, 5, 4, 3, 1]))