Maximum Product Difference Between Two Pairs Problem

Maximum Product Difference Between Two Pairs Problem — ExecCode Easy DSA Practice

Solve the Maximum Product Difference Between Two Pairs problem on ExecCode. Free online easy DSA practice in Sort. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given an integer array nums, choose four distinct indices w, x, y, and z such that the product difference between pairs (nums[w], nums[x]) and (nums[y], nums[z]) is maximized. Your task is to compute the required answer and return the maximum such product difference. The product difference between two pairs (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.

Examples

Input {"nums": [5, 6, 2, 7, 4]}; Output 34. Input {"nums": [9, 5, 8, 6, 7, 3, 2, 1, 4]}; Output 70. Input {"nums": [1, 2, 3, 4]}; Output 10

Constraints

4 <= nums.length <= 10^4 1 <= nums[i] <= 10^4

Practice Maximum Product Difference Between Two Pairs free on ExecCode. Browse DSA problems, topic map, and placement guides.