You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: solution/1800-1899/1874.Minimize Product Sum of Two Arrays/README_EN.md
+37-19
Original file line number
Diff line number
Diff line change
@@ -74,7 +74,13 @@ tags:
74
74
75
75
<!-- solution:start -->
76
76
77
-
### Solution 1
77
+
### Solution 1: Greedy + Sorting
78
+
79
+
Since both arrays consist of positive integers, to minimize the sum of products, we can multiply the largest value in one array with the smallest value in the other array, the second largest with the second smallest, and so on.
80
+
81
+
Therefore, we sort the array $\textit{nums1}$ in ascending order and the array $\textit{nums2}$ in descending order. Then, we multiply the corresponding elements of the two arrays and sum the results.
82
+
83
+
The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log n)$. Here, $n$ is the length of the array $\textit{nums1}$.
0 commit comments