Stock Maximize Discussions | | HackerRank

Stock Maximize

  • + 0 comments
    def stockmax(prices):
        last_price = prices[-1]
        max_profit = 0
        for key, price in enumerate(reversed(prices)):
            if not key:
                continue
            if price < last_price:
                max_profit += last_price - price
            else:
                last_price = price
        return max_profit