|
| 1 | +<h2><a href="https://leetcode.com/problems/minimize-product-sum-of-two-arrays">2029. Minimize Product Sum of Two Arrays</a></h2><h3>Medium</h3><hr><p>The <b>product sum </b>of two equal-length arrays <code>a</code> and <code>b</code> is equal to the sum of <code>a[i] * b[i]</code> for all <code>0 <= i < a.length</code> (<strong>0-indexed</strong>).</p> |
| 2 | + |
| 3 | +<ul> |
| 4 | + <li>For example, if <code>a = [1,2,3,4]</code> and <code>b = [5,2,3,1]</code>, the <strong>product sum</strong> would be <code>1*5 + 2*2 + 3*3 + 4*1 = 22</code>.</li> |
| 5 | +</ul> |
| 6 | + |
| 7 | +<p>Given two arrays <code>nums1</code> and <code>nums2</code> of length <code>n</code>, return <em>the <strong>minimum product sum</strong> if you are allowed to <strong>rearrange</strong> the <strong>order</strong> of the elements in </em><code>nums1</code>. </p> |
| 8 | + |
| 9 | +<p> </p> |
| 10 | +<p><strong class="example">Example 1:</strong></p> |
| 11 | + |
| 12 | +<pre> |
| 13 | +<strong>Input:</strong> nums1 = [5,3,4,2], nums2 = [4,2,2,5] |
| 14 | +<strong>Output:</strong> 40 |
| 15 | +<strong>Explanation:</strong> We can rearrange nums1 to become [3,5,4,2]. The product sum of [3,5,4,2] and [4,2,2,5] is 3*4 + 5*2 + 4*2 + 2*5 = 40. |
| 16 | +</pre> |
| 17 | + |
| 18 | +<p><strong class="example">Example 2:</strong></p> |
| 19 | + |
| 20 | +<pre> |
| 21 | +<strong>Input:</strong> nums1 = [2,1,4,5,7], nums2 = [3,2,4,8,6] |
| 22 | +<strong>Output:</strong> 65 |
| 23 | +<strong>Explanation: </strong>We can rearrange nums1 to become [5,7,4,1,2]. The product sum of [5,7,4,1,2] and [3,2,4,8,6] is 5*3 + 7*2 + 4*4 + 1*8 + 2*6 = 65. |
| 24 | +</pre> |
| 25 | + |
| 26 | +<p> </p> |
| 27 | +<p><strong>Constraints:</strong></p> |
| 28 | + |
| 29 | +<ul> |
| 30 | + <li><code>n == nums1.length == nums2.length</code></li> |
| 31 | + <li><code>1 <= n <= 10<sup>5</sup></code></li> |
| 32 | + <li><code>1 <= nums1[i], nums2[i] <= 100</code></li> |
| 33 | +</ul> |
0 commit comments