Challenge 1: Find Two Numbers that Add up to "s"

Given an array and a number 's', find two numbers from an array that sum to 's'. Implement your solution in C++ and see if your output matches with the correct output.

Problem Statement

Implement a function that takes an array arr, a number s, and the size of the array as an input, and returns two numbers which add up to s.

Input

An array, value, and size of the array

Output

An array with two integers that add up to s

Sample Input

arr = {1,21,3,14,5,60,7,6};
value = 81;

Sample Output

arr = {21,60};

For example, in this illustration we are given 81 as the number s. When we traverse the whole array, we find that 21 and 60 are the integers that add up to 81.

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.