Maximizing the Profit

  • + 0 comments

    I am using Python 3 and used combinations, but for some reason I am getting a timed out on some test cases:

    def maximumProfit(p):
        #
        # Write your code here.
        #
        max = -99999
        temp = 0
        if len(p) < 3:
            return -1
        c = list(combinations(p, 3))
        for i in c:
            if i[2] > i[1] and i[1] > i[0]:
                temp = i[0]*i[1]*i[2]
                if temp > max:
                    max = temp
        if max == -99999:
            return -1
        else:
            return(max)