Geeksforgeeks

X

DAYS

:

HOUR

:

MINS

:

SEC

Error

Copied to Clipboard

Given a set of integers, find distinct sum that can be generated from the subsets of the given sets.

**Example 1:**

**Input: **nums = {1,2}
**Output: **{1,2,3}
**Explanation: **Three distinict sum can be
calulated which are 1, 2 and 3.

**Example 2:**

**Input: **nums = {1,2,3}
**Output: **{1,2,3,4,5,6}
**Explanation: **Six distinict sum can be calculated
which are 1, 2, 3, 4, 5 and 6.

**Your Task:**

You don't need to read or print anything. Your task is to complete the function **DistinictSum() **which takes nums as input parameter and returns a list containing the distinict sum in increasing order,

**Expected Time Complexity: **O(n * sum) where sum = sum of all elements of nums.

**Expected Space Complexity: **O(n * sum)

**Constraints:**

1 <= length of nums <= 10^{2}

1 <= nums[i] <= 10^{2}

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Find all distinct subset (or subsequence) sums

...