#1913
Maximum Product Difference Between Two Pairs
newbie · 140 · lc easy +13 · verified · 83% accepted · 1,584 likes · top 94%
Description
The product difference between pair (a, b) and pair (c, d) is (a * b) - (c * d).
Given an integer array nums, choose four distinct indices w, x, y, and z to maximize (nums[w] * nums[x]) - (nums[y] * nums[z]).
Return that maximum product difference.
Example 1:
Input: nums = [5,6,2,7,4]
Output: 34
Explanation: We can choose indices 1 and 3 for the first pair (6, 7) and indices 2 and 4 for the second pair (2, 4).
The product difference is (6 * 7) - (2 * 4) = 34.
Example 2:
Input: nums = [4,2,5,9,7,4,8]
Output: 64
Explanation: We can choose indices 3 and 6 for the first pair (9, 8) and indices 1 and 5 for the second pair (2, 4).
The product difference is (9 * 8) - (2 * 4) = 64.
Code
1
2