id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

logic_allPossibleSums


Given an integer array, return all of the possible sums you could get by picking any number of integers (or none of them) from the array and adding them together.

For example, given an integer array of {1,2,3} you could sum none of them and get 0, or just sum 1 or 2 or 3 individually, or do 1+2=3 or 1+3=4 or 2+3=5 or 1+2+3=6.

Do not include any duplicate possibilities in your answer.


logic_allPossibleSums([1]) → [0, 1]
logic_allPossibleSums([1, 2]) → [0, 1, 2, 3]
logic_allPossibleSums([1, 2, 3]) → [0, 1, 2, 3, 4, 5, 6]

...Save, Compile, Run (ctrl-enter)

public int[] logic_allPossibleSums(int[] arr) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Post-solution available

Copyright Nick Parlante 2017 - privacy