Algorithms
Medium
2874
3152
Maximum Value of an Ordered Triplet II
maximum-value-of-an-ordered-triplet-ii
"""
You are given a 0-indexed integer array nums.

Return the maximum value over all triplets of indices (i, j, k) such that i < j < k. If all such triplets have a negative value, return 0.

The value of a triplet of indices (i, j, k) is equal to (nums[i] - nums[j]) * nums[k].

Example 1:

Input: nums = [12,6,1,2,7]
Output: 77
Explanation: 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.

Example 2:

Input: nums = [1,10,3,4,19]
Output: 133
Explanation: 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.

Example 3:

Input: nums = [1,2,3]
Output: 0
Explanation: 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.


Constraints:

 * 3 <= nums.length <= 105
 * 1 <= nums[i] <= 106
"""
class Solution:
    def maximumTripletValue(self, nums: List[int]) -> int:
        
You are given a 0-indexed integer array nums.

Return the maximum value over all triplets of indices (i, j, k) such that i < j < k. If all such triplets have a negative value, return 0.

The value of a triplet of indices (i, j, k) is equal to (nums[i] - nums[j]) * nums[k].

Example 1:

Input: nums = [12,6,1,2,7]
Output: 77
Explanation: 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.

Example 2:

Input: nums = [1,10,3,4,19]
Output: 133
Explanation: 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.

Example 3:

Input: nums = [1,2,3]
Output: 0
Explanation: 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.


Constraints:

 * 3 <= nums.length <= 105
 * 1 <= nums[i] <= 106


Please complete the code below to solve above prblem:
```python
class Solution:
    def maximumTripletValue(self, nums: List[int]) -> int:
        
```

my_solution = Solution()

test_input = { "nums": [12,6,1,2,7] }
assert my_solution.maximumTripletValue(**test_input) == 77

test_input = { "nums": [1,10,3,4,19] }
assert my_solution.maximumTripletValue(**test_input) == 133

test_input = { "nums": [1,2,3] }
assert my_solution.maximumTripletValue(**test_input) == 0

test_input = { "nums": [2,3,1] }
assert my_solution.maximumTripletValue(**test_input) == 0

test_input = { "nums": [5,7,8,4] }
assert my_solution.maximumTripletValue(**test_input) == 0

test_input = { "nums": [1000000,1,1000000] }
assert my_solution.maximumTripletValue(**test_input) == 999999000000

test_input = { "nums": [18,15,8,13,10,9,17,10,2,16,17] }
assert my_solution.maximumTripletValue(**test_input) == 272

test_input = { "nums": [8,6,3,13,2,12,19,5,19,6,10,11,9] }
assert my_solution.maximumTripletValue(**test_input) == 266

test_input = { "nums": [6,11,12,12,7,9,2,11,12,4,19,14,16,8,16] }
assert my_solution.maximumTripletValue(**test_input) == 190

test_input = { "nums": [15,14,17,13,18,17,10,19,2,20,12,9] }
assert my_solution.maximumTripletValue(**test_input) == 340

test_input = { "nums": [6,14,20,19,19,10,3,15,12,13,8,1,2,15,3] }
assert my_solution.maximumTripletValue(**test_input) == 285

test_input = { "nums": [2,7,19,4,8,20] }
assert my_solution.maximumTripletValue(**test_input) == 300

test_input = { "nums": [10,13,6,2] }
assert my_solution.maximumTripletValue(**test_input) == 14

test_input = { "nums": [1,19,1,3,18,10,16,9,3,17,8,9] }
assert my_solution.maximumTripletValue(**test_input) == 324

test_input = { "nums": [16,2,10,20,16,2,13,8,19] }
assert my_solution.maximumTripletValue(**test_input) == 342

test_input = { "nums": [19,11,12,4,17,1,7,20,13,10,14,20,11,19,3] }
assert my_solution.maximumTripletValue(**test_input) == 360

test_input = { "nums": [16,15,12,5,4,12,15,17,5,18,6,16,1,17,4] }
assert my_solution.maximumTripletValue(**test_input) == 289

test_input = { "nums": [8,10,17,11,2,8,13] }
assert my_solution.maximumTripletValue(**test_input) == 195

test_input = { "nums": [13,4,3,19,16,14,17,6,20,6,16,4] }
assert my_solution.maximumTripletValue(**test_input) == 260

test_input = { "nums": [1,8,9,18,4,10,3,13,9] }
assert my_solution.maximumTripletValue(**test_input) == 195

test_input = { "nums": [10,10,5,19,2] }
assert my_solution.maximumTripletValue(**test_input) == 95

test_input = { "nums": [15,3,3,18,19,13,7,5,18,1,8,5] }
assert my_solution.maximumTripletValue(**test_input) == 252

test_input = { "nums": [10,20,10] }
assert my_solution.maximumTripletValue(**test_input) == 0

test_input = { "nums": [14,9,4,20,9] }
assert my_solution.maximumTripletValue(**test_input) == 200

test_input = { "nums": [12,20,5,2,13,17,16,1,5,8,18,15,12] }
assert my_solution.maximumTripletValue(**test_input) == 342

test_input = { "nums": [7,1,17,17,4,20,14,20] }
assert my_solution.maximumTripletValue(**test_input) == 260

test_input = { "nums": [16,19,8,8,5,18,12,16,8,14,14,7,19] }
assert my_solution.maximumTripletValue(**test_input) == 266

test_input = { "nums": [17,9,13,7,3,5] }
assert my_solution.maximumTripletValue(**test_input) == 104

test_input = { "nums": [15,12,2,14,15,18,15,20,14,5,14,14,11,13,7] }
assert my_solution.maximumTripletValue(**test_input) == 260

test_input = { "nums": [17,20,17,13,5,12,8,12,14,10,14,20] }
assert my_solution.maximumTripletValue(**test_input) == 300

test_input = { "nums": [1,19,10] }
assert my_solution.maximumTripletValue(**test_input) == 0

test_input = { "nums": [11,16,10,15,10,5,7,3] }
assert my_solution.maximumTripletValue(**test_input) == 90

test_input = { "nums": [5,14,19,12,2,5,18,3,20,12,1,11] }
assert my_solution.maximumTripletValue(**test_input) == 340

test_input = { "nums": [10,8,12,14] }
assert my_solution.maximumTripletValue(**test_input) == 28

test_input = { "nums": [2,17,18,16,14,20,11,3,18,5,20,6,7] }
assert my_solution.maximumTripletValue(**test_input) == 340

test_input = { "nums": [19,12,3,19,2,18,3,12,9] }
assert my_solution.maximumTripletValue(**test_input) == 306

test_input = { "nums": [12,9,11,2,11,3,11,17,13,19] }
assert my_solution.maximumTripletValue(**test_input) == 190

test_input = { "nums": [8,13,9,8,7,18,20] }
assert my_solution.maximumTripletValue(**test_input) == 120

test_input = { "nums": [20,8,12,1,7,8,3,3,6] }
assert my_solution.maximumTripletValue(**test_input) == 152

test_input = { "nums": [8,2,16,6,14,14,13,2,11,5,2,12,15,3,3] }
assert my_solution.maximumTripletValue(**test_input) == 210

test_input = { "nums": [19,9,9,9,5] }
assert my_solution.maximumTripletValue(**test_input) == 90

test_input = { "nums": [19,10,5,13,6,9,5,15,19] }
assert my_solution.maximumTripletValue(**test_input) == 266

test_input = { "nums": [14,18,17,8,2,8,14] }
assert my_solution.maximumTripletValue(**test_input) == 224

test_input = { "nums": [11,5,17,13,5,8,8,19,17,1] }
assert my_solution.maximumTripletValue(**test_input) == 228

test_input = { "nums": [18,12,18,14,17,19] }
assert my_solution.maximumTripletValue(**test_input) == 114

test_input = { "nums": [18,17,8,8,18,9] }
assert my_solution.maximumTripletValue(**test_input) == 180

test_input = { "nums": [15,3,2,10,11,10,13,18] }
assert my_solution.maximumTripletValue(**test_input) == 234

test_input = { "nums": [17,17,5,10,19,1,16,3,1,19] }
assert my_solution.maximumTripletValue(**test_input) == 342

test_input = { "nums": [1,18,4,20,16] }
assert my_solution.maximumTripletValue(**test_input) == 280

test_input = { "nums": [6,20,4,4,2,19,14,10,9,7,20,5,8] }
assert my_solution.maximumTripletValue(**test_input) == 360

test_input = { "nums": [5,14,15,18,2,9,15,13,11,16,12,20] }
assert my_solution.maximumTripletValue(**test_input) == 320

test_input = { "nums": [7,19,17] }
assert my_solution.maximumTripletValue(**test_input) == 0

test_input = { "nums": [5,7,14,18,13,11,15,20,8,11,12,4,17,2,16] }
assert my_solution.maximumTripletValue(**test_input) == 288

test_input = { "nums": [4,12,7,2,8,6,9,5,4,1,8] }
assert my_solution.maximumTripletValue(**test_input) == 90

test_input = { "nums": [11,17,2,18,5] }
assert my_solution.maximumTripletValue(**test_input) == 270

test_input = { "nums": [19,13,2,2,19] }
assert my_solution.maximumTripletValue(**test_input) == 323

test_input = { "nums": [14,11,7,6,2,20,16,14,4,12,1,9,16,7,10] }
assert my_solution.maximumTripletValue(**test_input) == 304

test_input = { "nums": [8,15,6,16,16,9,6,14,4] }
assert my_solution.maximumTripletValue(**test_input) == 144

test_input = { "nums": [16,19,1,7,18,6,18,5,19,18,19] }
assert my_solution.maximumTripletValue(**test_input) == 342

test_input = { "nums": [16,14,11,2,17,9,10] }
assert my_solution.maximumTripletValue(**test_input) == 238

test_input = { "nums": [3,4,18,2,20,1,1,16,15,8,7,14,19,6] }
assert my_solution.maximumTripletValue(**test_input) == 361

test_input = { "nums": [12,20,14,18,11,16,16,9,12,5,14,17] }
assert my_solution.maximumTripletValue(**test_input) == 255

test_input = { "nums": [12,19,2,9,6] }
assert my_solution.maximumTripletValue(**test_input) == 153

test_input = { "nums": [17,19,14,7,10,18] }
assert my_solution.maximumTripletValue(**test_input) == 216

test_input = { "nums": [3,4,19,10,16,13,6,20] }
assert my_solution.maximumTripletValue(**test_input) == 260

test_input = { "nums": [11,6,8,9] }
assert my_solution.maximumTripletValue(**test_input) == 45

test_input = { "nums": [7,12,9,19,10,18,16,2,1,3,7,9,7,7] }
assert my_solution.maximumTripletValue(**test_input) == 162

test_input = { "nums": [20,9,20,7,3,7,19] }
assert my_solution.maximumTripletValue(**test_input) == 323

test_input = { "nums": [10,11,3,3,3,2,9,8] }
assert my_solution.maximumTripletValue(**test_input) == 81

test_input = { "nums": [4,20,15,1,17,2,2,4,10,15,2,8,16,6] }
assert my_solution.maximumTripletValue(**test_input) == 323

test_input = { "nums": [15,10,1,18,18,16,7,13,9,11] }
assert my_solution.maximumTripletValue(**test_input) == 252

test_input = { "nums": [10,6,17,11,15,15,18] }
assert my_solution.maximumTripletValue(**test_input) == 108

test_input = { "nums": [3,6,18] }
assert my_solution.maximumTripletValue(**test_input) == 0

test_input = { "nums": [4,7,20] }
assert my_solution.maximumTripletValue(**test_input) == 0

test_input = { "nums": [16,12,5] }
assert my_solution.maximumTripletValue(**test_input) == 20

test_input = { "nums": [4,17,15,12,2,16,16,13,6,20,14,17,18,16] }
assert my_solution.maximumTripletValue(**test_input) == 300

test_input = { "nums": [1,7,18,3,1,11,7,17] }
assert my_solution.maximumTripletValue(**test_input) == 289

test_input = { "nums": [18,16,10,2] }
assert my_solution.maximumTripletValue(**test_input) == 20

test_input = { "nums": [3,10,18,10,7,8] }
assert my_solution.maximumTripletValue(**test_input) == 88

test_input = { "nums": [8,6,20,20,4,12,14,7,13,16,12,15,12] }
assert my_solution.maximumTripletValue(**test_input) == 256

test_input = { "nums": [5,19,11,18,19,14,8,11,4,10] }
assert my_solution.maximumTripletValue(**test_input) == 152

test_input = { "nums": [17,1,16] }
assert my_solution.maximumTripletValue(**test_input) == 256

test_input = { "nums": [20,8,17,14,15,2,7,9,1,10,10,4,19,2,1] }
assert my_solution.maximumTripletValue(**test_input) == 361

test_input = { "nums": [9,16,16] }
assert my_solution.maximumTripletValue(**test_input) == 0

test_input = { "nums": [2,16,2,19,5,20,2,20,6,6] }
assert my_solution.maximumTripletValue(**test_input) == 360

test_input = { "nums": [18,3,6,17,4,20,14,6,13,9,5,11] }
assert my_solution.maximumTripletValue(**test_input) == 300

test_input = { "nums": [12,2,19,15,4,3,18,6,11,9,9,6,15] }
assert my_solution.maximumTripletValue(**test_input) == 288

test_input = { "nums": [10,15,10,13,7,18,18,3,13,15,20,4,6,15] }
assert my_solution.maximumTripletValue(**test_input) == 300

test_input = { "nums": [10,15,4,19,6,17,7,10,4,12,14,16,9,14] }
assert my_solution.maximumTripletValue(**test_input) == 240

test_input = { "nums": [17,6,3,8,13] }
assert my_solution.maximumTripletValue(**test_input) == 182

test_input = { "nums": [6,18,8,8,16,14,7,18] }
assert my_solution.maximumTripletValue(**test_input) == 198

test_input = { "nums": [7,7,2,19,16,11,3,15,3,15,16,17] }
assert my_solution.maximumTripletValue(**test_input) == 272

test_input = { "nums": [9,3,3,12,9,12,5,7,6,2,9,9,14,9,5] }
assert my_solution.maximumTripletValue(**test_input) == 140

test_input = { "nums": [19,14,15,1,20,10,20,4,10,20,15,15,2,7] }
assert my_solution.maximumTripletValue(**test_input) == 360

test_input = { "nums": [17,4,10,16,8,20,4,9,11,15,2,7] }
assert my_solution.maximumTripletValue(**test_input) == 260

test_input = { "nums": [3,8,17,10,10,20,20,8,14,20,1,10,1] }
assert my_solution.maximumTripletValue(**test_input) == 240

test_input = { "nums": [3,4,11,18,10,19,9,11,14,11,18,15,17,19,3] }
assert my_solution.maximumTripletValue(**test_input) == 190

test_input = { "nums": [18,10,5,16,13,1,19,10,17,14,14,20] }
assert my_solution.maximumTripletValue(**test_input) == 340

test_input = { "nums": [18,3,16,14,15,9,13,2,3] }
assert my_solution.maximumTripletValue(**test_input) == 240

test_input = { "nums": [2,6,19,10,19,14,18,8,3,2] }
assert my_solution.maximumTripletValue(**test_input) == 171