[
math
greedy
sort
]
Leetcode 1874 Minimize Product Sum of Two Arrays
Problem statement
https://leetcode.com/problems/minimize-product-sum-of-two-arrays/
Solution
Actually it is trans-inequality: minimim will be the smallest if for each biggest value in the first array we choose the smallest num in the second array.
Complexity
Time complexity is O(n log n), space is O(n)
Code
class Solution:
def minProductSum(self, nums1, nums2):
return sum(x*y for x,y in zip(sorted(nums1), sorted(nums2)[::-1]))