mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
36 lines
1.6 KiB
HTML
36 lines
1.6 KiB
HTML
<p>The <strong>product difference</strong> between two pairs <code>(a, b)</code> and <code>(c, d)</code> is defined as <code>(a * b) - (c * d)</code>.</p>
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
<li>For example, the product difference between <code>(5, 6)</code> and <code>(2, 7)</code> is <code>(5 * 6) - (2 * 7) = 16</code>.</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
<p>Given an integer array <code>nums</code>, choose four <strong>distinct</strong> indices <code>w</code>, <code>x</code>, <code>y</code>, and <code>z</code> such that the <strong>product difference</strong> between pairs <code>(nums[w], nums[x])</code> and <code>(nums[y], nums[z])</code> is <strong>maximized</strong>.</p>
|
|
|
|
|
|
|
|
<p>Return <em>the <strong>maximum</strong> such product difference</em>.</p>
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
<strong>Input:</strong> nums = [5,6,2,7,4]
|
|
|
|
<strong>Output:</strong> 34
|
|
|
|
<strong>Explanation:</strong> 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.
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
<strong>Input:</strong> nums = [4,2,5,9,7,4,8]
|
|
|
|
<strong>Output:</strong> 64
|
|
|
|
<strong>Explanation:</strong> 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.
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
<li><code>4 <= nums.length <= 10<sup>4</sup></code></li>
|
|
|
|
<li><code>1 <= nums[i] <= 10<sup>4</sup></code></li>
|
|
|
|
</ul> |