Skip to main content
Back to problems
Leetcode
Medium
Arrays
Math
Google
Maximum Value Of An Ordered Triplet I

Find the maximum value of an ordered triplet expression over an integer array.

Acceptance 0%
Problem Statement

Given an integer array nums, choose indices i, j, and k such that i < j < k. Compute the value of the ordered triplet expression

(nums[i]−nums[j])×nums[k](nums[i] - nums[j]) \times nums[k]

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.

Input Format

  • A single integer array nums.
  • The array contains at least 3 elements.

Output Format

  • Return one integer: the maximum value of (nums[i] - nums[j]) * nums[k] over all indices i < j < k.

Constraints

  • 3 <= nums.length
  • The exact value ranges are not provided in the source metadata.
  • A correct solution should avoid brute force over all triplets when possible.
Examples
Sample cases returned by the problem API.

Example 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

Unlock deeper context for this problem

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.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.