Challenge : sum finder | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Challenge : sum finder

Make a function that takes an array with N distinct integers and a target S and returns the number of ways to add at most N numbers (duplicates allowed) taken from.the array and reach a sum S. Ex : [1,2,3],7 => 2 ways to sum to 7 because 3+3+1=3+2+2=7 (1+1+1+1+1+1+1 or 3+1+1+2 dont work because it needs more than 3 numbers)

28th Oct 2017, 6:22 PM
VcC
VcC - avatar
6 Answers
+ 2
as u said... a bonus one liner... change...sum number change array for further checking https://code.sololearn.com/cjtIVHtkAmOH/?ref=app
28th Oct 2017, 8:24 PM
sayan chandra
sayan chandra - avatar
+ 11
Interesting challenge, thank you 👍 Here's my try : https://code.sololearn.com/cUS6UH5Dxmql/?ref=app
14th Nov 2017, 11:48 AM
LukArToDo
LukArToDo - avatar
+ 1
heres mine... ## i initialised the array...as 1, 2, 3, 4 ## u can change it to anything u want ## input the number to het summed up ## Bonus>> it will show u each combination from 1 to your entered number ((time limit may exceed for higher numbers)) ((try 20 *just a random perfect example*)) https://code.sololearn.com/cafLUYjbOfCS/?ref=app
28th Oct 2017, 6:47 PM
sayan chandra
sayan chandra - avatar
0
The answers must have at most N numbers :-(
28th Oct 2017, 8:43 PM
VcC
VcC - avatar
- 1
Bonus for whoever does a one liner functional version !
28th Oct 2017, 7:53 PM
VcC
VcC - avatar