We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2908d74 commit d1a2b04Copy full SHA for d1a2b04
MinimizeProductSumOfTwoArrays/solution.cpp
@@ -0,0 +1,18 @@
1
+class Solution {
2
+public:
3
+ int minProductSum(vector<int>& nums1, vector<int>& nums2)
4
+ {
5
+ // sort both vectors in differing orders so the biggest values dont multiply with each other
6
+ sort(nums1.begin(), nums1.end()); // sort accending order
7
+ sort(nums2.rbegin(), nums2.rend()); // sort descending order
8
+
9
+ // Calc dot product sum
10
+ int sum = 0;
11
+ for (int i=0; i<nums1.size(); i++)
12
13
+ sum += nums1[i] * nums2[i];
14
+ }
15
16
+ return sum;
17
18
+};
0 commit comments