The two-sum interview question is interesting to explore because it has both a brute force, logical solution, as well as a more time-efficient solution that can demonstrate strong computer science fundamentals. Let’s explore both potential solutions and hopefully learn along the way!
The Two-Sum Question
First, let’s understand the two-sum question. It’s usually posed as some form of the following:
You are asked to create a function that takes two parameters. The first parameter, , is an array of numbers. The second parameter, is a single number. The output of the function should be a two-element array that represents a pair of numbers in that add up to .