Stock Maximize Discussions | Algorithms | HackerRank
  • + 0 comments
    def stockmax(prices):
        res = 0
        while prices:
            max_price = max(prices)
            idx_max = prices.index(max_price)
            cur_pft = sum([max_price - p for p in prices[:idx_max]])
            res += cur_pft
            prices = prices[idx_max+1:]
        return res