Skip to content

Practice Find Array Given Subset Sums

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#1982
LeetCode Problem

Find Array Given Subset Sums

Problem Statement

Given n and the unordered list sums of all 2^n subset sums of an unknown length-n array, return any array consistent with that list. Subsets choose indices, so equal sums can occur repeatedly; the empty subset contributes 0. At least one valid answer is guaranteed.

Source: Find Array Given Subset Sums on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 3, sums = [-3,-2,-1,0,0,1,2,3]
Output
[1,2,-3]

# Example 2

Input
n = 2, sums = [0,0,0,0]
Output
[0,0]

# Example 3

Input
n = 4, sums = [0,0,5,5,4,-1,4,9,9,-1,4,3,4,8,3,8]
Output
[0,-1,4,5]

Constraints

1 <= n <= 15
sums.length == 2^n
-10^4 <= sums[i] <= 10^4

Related LeetCode Problems

Practice more problems similar to Find Array Given Subset Sums.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.