- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# C++ program to find two numbers from two arrays whose sum is not present in both arrays

Suppose we have two arrays A with n elements and B with m elements. Select some element a form A and some element b from B, such that a + b does not belong to A or B.

So, if the input is like A = [3, 2, 2]; B = [1, 5, 7, 7, 9], then the output will be [3, 1], because 3 + 1 = 4 is not present in any array. (Other answers are also available)

## Steps

To solve this, we will follow these steps −

sort the array A sort the array B return last element of A and last element of B

## Example

Let us see the following implementation to get better understanding −

#include <bits/stdc++.h> using namespace std; void solve(vector<int> A, vector<int> B) { sort(A.begin(), A.end()); sort(B.begin(), B.end()); cout << A[A.size() - 1] << ", " << B[B.size() - 1]; } int main() { vector<int> A = { 3, 2, 2 }; vector<int> B = { 1, 5, 7, 7, 9 }; solve(A, B); }

## Input

{ 3, 2, 2 }, { 1, 5, 7, 7, 9 }

## Output

3, 9

- Related Articles
- Add two numbers represented by two arrays in C Program
- Find Sum of pair from two arrays with maximum sum in C++
- Count pairs from two sorted arrays whose sum is equal to a given value x in C++
- Maximum sum by picking elements from two arrays in order in C++ Program
- Find sub-arrays from given two arrays such that they have equal sum in Python
- Count Pairs from two arrays with even sum in C++
- Find the overlapping sum of two arrays using C++
- Count pairs from two arrays having sum equal to K in C++
- Count pairs from two arrays whose modulo operation yields K in C++
- Maximum OR sum of sub-arrays of two different arrays in C++
- Maximum Sum Path in Two Arrays in C++
- Java Program to Find the closest pair from two sorted arrays
- Program to find minimum operations needed to make two arrays sum equal in Python
- Program to find uncommon elements in two arrays - JavaScript
- Find the closest pair from two sorted arrays in c++

Advertisements