Given a array arr of integers, return the sums of all subsets in the list. Return the sums in sorted order.
Example 1
Input: arr[] = [1, 3]
Output: [0, 1, 3, 4]
Explanation: The possible subset sums are: 0 (empty subset). 1 (from the element 1). 3 (from the element 3). 4 (from the combination of 1 and 3). These are all the subset sums of the array [1, 3]. The sums are returned in any order.
Example 2
Input: arr[] = [2, 5, 7]
Output: [0, 2, 5, 7, 7, 12, 14, 17]
Explanation: The possible subset sums of the array [2, 5, 7] are 0 (from the empty subset), 2 (from the element 2), 5 (from the element 5), 7 (from the element 7), 7 (from the combination of 2 and 5), 12 (from the combination of 2 and 7), 14 (from the combination of 5 and 7), and 17 (from the combination of 2, 5, and 7). These are all the subset sums, which are returned in any order.
Sign in to write, run, and submit your solution against the full test suite.