Tap here to switch tabs
Problem
Submissions

Problem: Maximum Value of an Ordered Triplet II

Maximum Value of an Ordered Triplet II asks you to select three increasing array indices and maximize the difference between the first two values times the third, or zero when all are negative.

Statement

You are given an integer array nums.

An ordered triplet consists of three indices (i, j, k) such that i << j << k. The value of such a triplet is evaluated as (nums[i] −- nums[j]) $ imes$ nums[k].

Return the maximum value among all ordered triplets in nums. If every triplet yields a negative value, return 00.

Constraints:

  • 3≤3 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤106\leq 10^6

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Value of an Ordered Triplet II

Maximum Value of an Ordered Triplet II asks you to select three increasing array indices and maximize the difference between the first two values times the third, or zero when all are negative.

Statement

You are given an integer array nums.

An ordered triplet consists of three indices (i, j, k) such that i << j << k. The value of such a triplet is evaluated as (nums[i] −- nums[j]) $ imes$ nums[k].

Return the maximum value among all ordered triplets in nums. If every triplet yields a negative value, return 00.

Constraints:

  • 3≤3 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤106\leq 10^6