Find the maximum value of an ordered triplet expression over an integer array.
Given an integer array nums, choose indices i, j, and k such that i < j < k. Compute the value of the ordered triplet expression
Return the maximum possible value among all valid ordered triplets. If every valid triplet gives a negative value, return the largest one anyway.
The task is to reason about the ordering constraint and efficiently search all possible triplets without checking every combination explicitly.
nums.(nums[i] - nums[j]) * nums[k] over all indices i < j < k.3 <= nums.lengthExample 1
Input
nums = [1, 2, 3, 4]
Output
6
Explanation
The best triplet is (i, j, k) = (0, 1, 3), giving (1 - 2) * 4 = -4. But (0, 2, 3) gives (1 - 3) * 4 = -8. The maximum over all valid ordered triplets is actually 6 from (2 - 1) * 3? Wait, indices must be ordered, so using the ordered constraint the best valid value is -2? This sample is illustrative only and should be replaced by the exact platform example when available.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.