Final answer:
To find the smallest n sums out of nⁿ possible sums, we can use a combination of sorting and heap data structure.
Step-by-step explanation:
To find the smallest n sums out of nⁿ possible sums, we can use a combination of sorting and heap data structure. Here is an O(n² log(n)) algorithm:
- Create an empty min-heap and insert the first element from each array into the heap.
- Repeat the following n times:
- Extract the minimum element from the heap and add it to the result list.
- Replace the extracted element with the next element from its respective array.
- If the array still has elements, insert the new element into the heap.
The result list will contain the smallest n sums of the given arrays. In the example you provided, the smallest n sums are [9, 10, 12].