Ctrl K

A Drop Times a Third

Easy
You are given an array of positive integers values. For 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, 8, 3] → 56

Indices (0, 2, 3) give (9 − 2) · 8 = 56, and nothing beats that.

Example 2
values=[2, 5, 9] → 0

The only triple gives (2 − 5) · 9 = −27, which is negative, so the answer is 0.

Example 3
values=[5, 1, 6, 3, 10] → 40
Constraints
  • 3 ≤ len(values) ≤ 100
  • 1 ≤ values[i] ≤ 10⁶
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPair With a Target Sum EasySqueeze Repeats Out of a Sorted Array EasyDrop the Unwanted Value EasySlot on a Sorted Shelf EasyAdd One to a Digit Array Easy
loading Python…
Input
values=[9, 4, 2, 8, 3]
Expected
56

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