Free written solutionMaximum Value of an Ordered Triplet I (LeetCode 2873): Solution and Explanation
For indices i < j < k, a triplet is worth (nums[i] - nums[j]) * nums[k]. Return the largest value over all triplets, or 0 if every triplet is negative. For [12,6,1,2,7] the answer is 77. Products reach 10^12, so the result is a 64-bit integer.
Read the intuition, approach, code and complexity →