Count Pairs Problem Statement
You are given an array A
of length N
consisting only of integers. Additionally, you are provided with three integers X
, Y
and SUM
. Your task is to count the number of pairs (i, j)
where i < j
such that (A[i] * X + A[j] * Y) == SUM
.
Input:
The input starts with an integer T
, representing the number of test cases. Each test case consists of:
1. A single line containing four integers: N
, X
, Y
, SUM
where N
is the size of the array, X
and Y
are multipliers, and SUM
is the target sum.
2. The next line contains N
space-separated integers that make up the array A
.
Output:
For each test case, output a single integer that denotes the number of pairs (i, j)
where (A[i]*X + A[j]*Y) == SUM
.
Output each result on a new line.
Example:
Input:
N = 3, A = {3, 1, 2, 3}, X = 4, Y = 2, SUM = 14
Output:
2
Explanation:
The possible valid pairs based on the condition are (1, 3)
and (3,4)
as they both satisfy the equation.
Constraints:
1 <= T <= 10
1 <= N <= 105
1 <= X, Y <= 104
1 <= SUM <= 109
0 <= A[i] <= 105
It is guaranteed that the count of pairs will fit in a 32-bit integer.
The sum of N
across all test cases is <= 105.
Time limit: 1 second.
Be the first one to answer
Add answer anonymously...
Top Optum Global Solutions Software Developer interview questions & answers
Popular interview questions of Software Developer
>
Optum Global Solutions Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app