Array algorithm, noting complexity


Given an array of length N and a number X, write a function to return True if there are two numbers in the array that sum to the given number X.

For example:

[1, 2, 3, 4], 7 -> returns True since 3 + 4 sum to 7
[1, 6, 3, 5], 5 -> returns False since no *two* numbers sum to 5

For simplicity, you can assume that there are no duplicate numbers in the array. Lastly, be sure to describe the complexity (Big O notation) of your solution, and see if you can come up with something that is at least linear (O(n)).


Access restricted

Subscribe to premium account to see the solution.

Get premium now