Stock Maximize Discussions | | HackerRank

Stock Maximize

  • + 0 comments
    def stockmax(prices):
        profit = 0
        maxPrice = 0
        for price in prices[::-1]:
            if price > maxPrice:
                maxPrice = price
            else:
                profit += maxPrice - price
        return profit