The title

The product difference between two pairs of numbers (a, b) and (c, d) is defined as (a * b) – (c * d).

For example, the product difference between (5, 6) and (2, 7) is (5 * 6) – (2 * 7) = 16. Given an integer array nums, select four different subscripts w, x, y, and z to maximize the product difference between the pairs (nums[w], nums[x]) and (nums[y], nums[z]).

Returns the maximum value of the product difference obtained in this manner.

 

Example 1: input: nums = [5,6,2,7,4] output: 34 Elements with subscripts 1 and 3 can be selected to form the first pair (6, 7) and subscripts 2 and 4 to form 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]; nums = [4,2,5,9,7,4]Copy the code

Tip:

4 <= nums.length <= 104 1 <= nums[i] <= 104

Their thinking

class Solution: def maxProductDifference(self, nums: List[int]) -> int: nums.sort() # print(nums) res = (nums[-1]*nums[-2] - nums[0]*nums[1]) return res if __name__ == '__main__': Nums = [4,2,5,9,7,4,8] ret = Solution(). Print (ret)Copy the code