Ctrl K

Drop, Then Multiply

Medium
You get an integer array values. For any three indices i < j < k, the value of the triple is (values[i] - values[j]) * values[k]. Return the largest value over all such triples. If every triple has a negative value, return 0.
Example 1
values=[9, 4, 2, 5, 3] → 35

The index triple (0, 2, 3) gives (9 − 2) · 5 = 35, and nothing beats it.

Example 2
values=[2, 4, 8] → 0

The only triple gives (2 − 4) · 8 = −16 < 0, so the answer is 0.

Example 3
values=[6, 1, 10, 1, 7] → 63
Constraints
  • 3 ≤ len(values) ≤ 10⁵
  • 1 ≤ values[i] ≤ 10⁶
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsTwo Boards Holding Water MediumZero-Sum Triples MediumTriple Sum Nearest the Target MediumFour Numbers to a Target MediumNext Arrangement in Order Medium
loading Python…
Input
values=[9, 4, 2, 5, 3]
Expected
35

Run checks the first 3 tests in your browser. Submit checks all 116 tests on the server, hidden ones included.