<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>.</p>

<p>Return <em><strong>the maximum value over all triplets of indices</strong></em> <code>(i, j, k)</code> <em>such that</em> <code>i &lt; j &lt; k</code><em>. </em>If all such triplets have a negative value, return <code>0</code>.</p>

<p>The <strong>value of a triplet of indices</strong> <code>(i, j, k)</code> is equal to <code>(nums[i] - nums[j]) * nums[k]</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [12,6,1,2,7]
<strong>Output:</strong> 77
<strong>Explanation:</strong> The value of the triplet (0, 2, 4) is (nums[0] - nums[2]) * nums[4] = 77.
It can be shown that there are no ordered triplets of indices with a value greater than 77. 
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,10,3,4,19]
<strong>Output:</strong> 133
<strong>Explanation:</strong> The value of the triplet (1, 2, 4) is (nums[1] - nums[2]) * nums[4] = 133.
It can be shown that there are no ordered triplets of indices with a value greater than 133.
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,2,3]
<strong>Output:</strong> 0
<strong>Explanation:</strong> The only ordered triplet of indices (0, 1, 2) has a negative value of (nums[0] - nums[1]) * nums[2] = -3. Hence, the answer would be 0.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>3 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
	<li><code>1 &lt;= nums[i] &lt;= 10<sup>6</sup></code></li>
</ul>

class Solution:
    def maximumTripletValue(self, nums: List[int]) -> int:
        if len(nums) == 3:
            if (nums[0] - nums[1])*nums[2] > 0: 
                return((nums[0]-nums[1])*nums[2])
        # elif len(nums) == 4:
        #     if ((nums[0] - nums[1])*nums[2]) > 0 or ((nums[1] - nums[2])*nums[3]) or ((nums[0] - nums[1])*nums[3]) > 0 or ((nums[0] - nums[2])*nums[3]) > 0: 
        #         return max( (nums[0] - nums[1])*nums[2], (nums[1] - nums[2])*nums[3], (nums[0] - nums[1])*nums[3], (nums[0] - nums[2])*nums[3])
        #     else:
        #         return 0
                
        prefix_max = [0]*len(nums)
        suffix_max = [0]*len(nums)

        # for i in range(len(nums)):
        #     if i == 0:
        #         prefix_max[0] = nums[0]
        #         suffix_max[0] = max(nums)
        #     else:
        #         prefix_max[i] = max(nums[0:i+1])
        #         suffix_max[i] = max(nums[i:])

        for i in range(len(nums)):
            if i == 0:
                prefix_max[0] = nums[0]
            else:
                prefix_max[i] = max((prefix_max[i-1]), nums[i])
        
        for i in range(len(nums)-1,-1,-1):
            if i == len(nums)-1:
                suffix_max[len(nums)-1] = nums[len(nums)-1]
            else:
                suffix_max[i] = max((suffix_max[i+1]), nums[i])
            
        
        print(prefix_max, suffix_max)

        overall_max_triplet_val = -1

        for i in range(1,len(nums)-1):
            max_triplet_val = (prefix_max[i-1] - nums[i])*suffix_max[i+1]
            if max_triplet_val > overall_max_triplet_val:
                overall_max_triplet_val = max_triplet_val
        
        print(overall_max_triplet_val)
        if overall_max_triplet_val < 0:
            return 0
        else:
            return overall_max_triplet_val
847