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.
Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle. It only takes a minute to sign up.Sign up to join this community
This is what i could analyze in a minute or two to make a pattern:
Since you didn't say they had to be integers (or different numbers)
Number - Number
Number - Number/2 - Number/2
Number - Number/3 - Number/3 - Number/3
Easy pattern to toss in a loop - though @gpmattoo has a much more elegant solution. (The sum of the first X number minus that sum as the last number).