1982. Find Array Given Subset Sums
https://leetcode.com/problems/find-array-given-subset-sums
Description
You are given an integer n
representing the length of an unknown array that you are trying to recover. You are also given an array sums
containing the values of all 2n
subset sums of the unknown array (in no particular order).
Return the array ans
of length n
representing the unknown array. If multiple answers exist, return any of them.
An array sub
is a subset of an array arr
if sub
can be obtained from arr
by deleting some (possibly zero or all) elements of arr
. The sum of the elements in sub
is one possible subset sum of arr
. The sum of an empty array is considered to be 0
.
Note: Test cases are generated such that there will always be at least one correct answer.
Example 1:
Example 2:
Example 3:
Constraints:
1 <= n <= 15
sums.length == 2n
-104 <= sums[i] <= 104
ac
Last updated