Quant Memo
Coding/●●●●

The k pairs with the smallest sums

Asked at HRT, SIG

Given two ascending arrays nums1 and nums2 and an integer k, return the k pairs (a, b) (one element from each array) with the smallest sums a + b, in nondecreasing order of sum.

nums1 = [1, 7, 11]
nums2 = [2, 4, 6]
k = 3   ->   [[1, 2], [1, 4], [1, 6]]

Aim for O(klogk)O(k \log k) time and O(k)O(k) memory.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions