logo CodeStepByStep logo

ThreeSum

Language/Type: C# arrays loops algorithms interview
Related Links:

Write a method named ThreeSum that accepts an array of integers and prints all combinations of three integers in the list that sum to 0. For example, if given the array [-1, 0, 1, 2, -1, -4], print the following lines of output:

-1 0 1
-1 -1 2
0 1 -1

You may print the lines of output in any order. Do not print duplicate arrays; if the same exact subarray can be made in multiple ways, print it only once. If there are no combinations of three elements that sum to 0, print no output.

Method: Write a C# method as described, not a complete program or class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.