Ctrl K

Widest Gap Between Two Products

Easy
You are given an array of positive integers values. Pick four elements at different indices and split them into two pairs. Subtract the product of the second pair from the product of the first. Return the largest result you can get this way.
Example 1
values=[3, 9, 1, 6, 2] → 52

The first pair is 9 and 6 (product 54), the second is 1 and 2 (product 2). The difference is 54 − 2 = 52.

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

Whatever you pick, both pairs give 25, so the difference is 0.

Example 3
values=[10, 1, 3, 10, 2, 7] → 98
Constraints
  • 4 ≤ len(values) ≤ 10⁴
  • 1 ≤ values[i] ≤ 10⁴
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsMerge Into the Spare Tail EasyThe Candidate With Most Votes EasyDoes Any Value Repeat EasyMake It to Every Meeting EasyThe Lost Ticket Easy
loading Python…
Input
values=[3, 9, 1, 6, 2]
Expected
52

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