Class Solution
-
- All Implemented Interfaces:
public final class Solution2874 - Maximum Value of an Ordered Triplet II\.
Medium
You are given a 0-indexed integer array
nums.Return the maximum value over all triplets of indices
(i, j, k)such thati < j < k. If all such triplets have a negative value, return0.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 (nums0 - nums2) \* nums4 = 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 (nums1 - nums2) \* nums4 = 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 (nums0 - nums1) \* nums2 = -3. Hence, the answer would be 0.
Constraints:
<code>3 <= nums.length <= 10<sup>5</sup></code>
<code>1 <= numsi<= 10<sup>6</sup></code>
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final LongmaximumTripletValue(IntArray nums)-
-
Method Detail
-
maximumTripletValue
final Long maximumTripletValue(IntArray nums)
-
-
-
-