why would you use recursion here at all?
I don't see the reason for it.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
if you sort it DESCENDING you can loop through the array subbing the element from the total sum, if the next element causes the result to fall below zero you skip it for example
sum = 15
integers: 10, 4, 3, 1
we loop through and take 10 from 15 leaving 5
take 4 from 5 leaving 1
take 3 from 1 leaving -2 : skip it
take 1 from 1 leaving 0 : stop on zero
result = 10+4+1 = 15
Hope this helps :)
This is no good for the next array: 10 4 3 2
Srcee
Junior Poster in Training
59 posts since May 2010
Reputation Points: 10
Solved Threads: 0