Categorygithub.com/ductnn/coding-practicealgoexpertCoding-Interview-QuestionsArraysGreentwo-number-sum
package
0.0.0-20241225161807-6c2a4c2dbe8f
Repository: https://github.com/ductnn/coding-practice.git
Documentation: pkg.go.dev
# README
Two number sum
Problem
-
Difficulty: Green, Category: Arrays
Write a function that takes in a non-empty array of distinct integers and an integer representing a target sum. If any two numbers in the input array sum up to the target sum, the function should return them in an array, in any order. If no two numbers sum up to the target sum, the function should return an empty array.
You can assume that there will be at most one pair of numbers summing up to the target sum.
Note that the target sum has to be obtained by summing two different integers in the array; you can't add a single integer to itself in order to obtain the target sum.
Sample Input
arrays = [3, 5, -4, 8, 11, 1, -1, 6] targetSum = 10
Sample Output
[-1, 11]