Skip to content

Latest commit

 

History

History
executable file
·
25 lines (12 loc) · 773 Bytes

Three_Number_Sum.md

File metadata and controls

executable file
·
25 lines (12 loc) · 773 Bytes

Three Number Sum

Problem Statement

Write a function that takes in a non-empty array of distinct integers and an integer representing a target sum. The function should nd all triplets in the array that sum up to the target sum and return a two-dimensional array of all these triplets. The numbers in each triplet should be ordered in ascending order, and the triplets themselves should be ordered in ascending order with respect to the numbers they hold. If no three numbers sum up to the target sum, the function should return an empty array.

Sample input: [12, 3, 1, 2, -6, 5, -8, 6], 0

Sample output: [[-8, 2, 6], [-8, 3, 5], [-6, 1, 5]]

Explanation

We can use a Stack here

Solution

Check this Python code.