Question
Number of Pairs With Target Sum
1 3 5 7
2 3 5 8
You are given two arrays arr1 and arr2 consisting of distinct integers. You are also given an integer x.
Your task is to count the number of pairs (i, j) such that:
- The element
arr1[i]is taken from the first array. - The element
arr2[j]is taken from the second array. - The sum
arr1[i] + arr2[j] = x.
Note: Each valid pair must contain one element from arr1 and one element from arr2.
Input
- The first line contains an integer
x. - The second line contains the elements of array
arr1. - The third line contains the elements of array
arr2.
Output
Print a single integer — the count of valid pairs whose sum is equal to x.
Example
Input:
101 3 5 7
2 3 5 8
Output:
2Explanation:
- The valid pairs whose sum is
10are(5, 5)and(7, 3). - Each pair contains one element from the first array and one from the second array.