Challenge: Find Two Numbers that Add up to "value"

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

Problem Statement

Implement a function findSum(int arr[], int value, int size) which takes an array arr, a number value and size of the array as input and returns an array of two numbers that add up to value. In case there is more than one pair in the array containing numbers that add up to value, you are required to return only one such pair. If no such pair is found then return an empty array.

Input

An array, value, and size of the array.

Output

An array with two integers that add up to value.

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 value and 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 70+ hands-on prep courses.