Sets of numbers that sum to a certain number

numberspuzzles

I was asked this in an interview, and I'm not sure what the answer is or how to approach the problem.

Find a pair of numbers that sum up to zero (or any other number), then find three (and then four) numbers that sum up to zero.

Best Answer

Use the following equality 1+2+3+...+n=n(n+1)/2.

1+(-1) = 0

1+2+(-3) = 0

1+2+3+(-6) = 0

...

1+2+3+...+n+(-n(n+1)/2) = 0

Related Topic