Statement▼
Given two lists and an integer k, find k pairs of numbers with the smallest sum so that in each pair, each list contributes one number to the pair.
Constraints:
-
1 ≤
list1.length
,list2.length
≤ 500 -
−104 ≤
list1[i]
,list2[i]
≤ 104 -
1 ≤ k ≤ 103
-
Input lists should be sorted in ascending order.
-
If the value of k exceeds the total number of valid pairs that may be formed, return all the pairs.