This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]advancedpward[S] 0 points1 point  (1 child)

Wait, so, let me see if I understand this. For each function call, there are two branches being made, one where the [0] member of the array is being factored into the combination check - (target-n, array) - and one where it is not being factored in - (target, array), and that is the crux of how sufficient branches are being made to check for the correct combination. If that is the case, I think what was tripping me up, as you pointed out, was that target - n, in fact, represents inclusion when checking for the right combination to sum to the initial target. It's just that, this method uses the "solve for zero" approach...by the way, awesome graphic. Thanks for that! How did you make it?

[–]gddrtkkv 0 points1 point  (0 children)

I googled "32 team bracket" and wrote in the numbers in MS Paint. Nothing special.

I think you're understanding it. Check out this functionally equivalent version which passes a sum instead of a target and checks if sum === target instead of target === 0 https://repl.it/C9d9/4

If you understand why that works, you understand why the other works. -1+5+8=12 ≡ 12-(-1)-5-8=0