Stock Maximize Discussions | | HackerRank

Stock Maximize

  • + 0 comments
    def stockmax(prices):
        # Write your code here
        x = max(prices)
        firstIndex = prices.index(x)
        if(firstIndex == 0):
            res = 0
        else:
            res = -1*sum(prices[0:firstIndex]) + firstIndex*x
        if(firstIndex+1 == len(prices)):
            return res
        else:
            return res + stockmax(prices[firstIndex+1:])