All problems
0071EasyArrayMathSorting

Largest Triple Drift

Tracked in this browser only
Write code

Trains the technique from

LeetCode 628Maximum Product of Three Numbers

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A calibration rig logs how far a gauge drifted each shift. drifts[i] is the signed drift for shift i, negative when the gauge fell short and positive when it overshot.

The rig's stress score for three shifts is the product of their three drift values. Pick three shifts at three different positions and return the largest stress score reachable.

Note that two badly negative drifts multiply into a large positive number, so the three biggest values are not always the winning pick.

Examples

Example 1

Input
drifts = [3, 5, 1, 8]
Output
120

Every value is positive, so the three largest, 3, 5 and 8, give the best score of 120.

Example 2

Input
drifts = [-9, -8, 1, 2]
Output
144

Taking -9 and -8 together cancels both signs, and pairing them with 2 beats the 1 * 2 * -8 available from the three largest values.

Example 3

Input
drifts = [-5, -4, -3]
Output
-60

Only one triple exists, and its score is negative; that is still the answer.

Constraints

  • 3 <= drifts.length <= 10^4
  • -1000 <= drifts[i] <= 1000

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def largest_triple_drift(drifts: list[int]) -> int:
Java
public int largestTripleDrift(int[] drifts)
September 7
Apply