Return the pairs formed from two sorted arrays that have the smallest sums.
You are given two integer arrays nums1 and nums2, each sorted in non-decreasing order, and an integer k.
Form pairs (u, v) where u comes from nums1 and v comes from nums2. Your task is to return the k pairs with the smallest sums u + v.
If fewer than k pairs exist, return all of them.
[u, v].nums1: a sorted integer arraynums2: a sorted integer arrayk: an integerk pairs [u, v] with the smallest sums.1 <= nums1.length, nums2.lengthk >= 1k exceeds the total number of possible pairs, return all pairsExample 1
Input
nums1 = [1, 7, 11] nums2 = [2, 4, 6] k = 3
Output
[[1,2],[1,4],[1,6]]
Explanation
The three smallest pair sums are 3, 5, and 7, produced by pairs [1,2], [1,4], and [1,6].
Example 2
Input
nums1 = [1, 1, 2] nums2 = [1, 2, 3] k = 2
Output
[[1,1],[1,1]]
Explanation
The smallest sums are both 2, coming from the two distinct pairs that use the first two 1s from nums1 with 1 from nums2.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.