Do two array elements sum to N?

Question

Given an array and a number N, write a function that returns True if there are two numbers in the array that add up to N. Otherwise, return False.

For example:

[1, 2, 3, 4], 5 -> returns True, 4+1 and 2+3 both equal 5
[1, 2, 3, 1], 5 -> returns True, 2+3 both equal 5
[1, 1, 2, 1], 5 -> returns False, no number add up to 5

Solution

Access restricted

Subscribe to premium account to see the solution.

Get premium now