Copied to Clipboard
Find all distinct subset (or subsequence) sums
Medium Accuracy: 51.49% Submissions: 624 Points: 4

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)


1 <= length of nums <= 102

1 <= nums[i] <= 102

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

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?


All Submissions

My Submissions:

Login to access your submissions.

Find all distinct subset (or subsequence) sums

Output Window