Number of pairs
Medium Accuracy: 10.01% Submissions: 1508 Points: 4

Given two arrays X[] and Y[] of size M and N respectively. Find number of pairs such that xy > yx where x is an element from X[] and y is an element from Y[].

Example 1:

Input:
M = 3, N = 2
X[] = {2, 1, 6}, Y = {1, 5}
Output: 3
Explanation: There are total 3 pairs 
where pow(x, y) is greater than pow(y, x) 
Pairs are (2, 1), (2, 5) and (6, 1).


Example 2:

Input:
M = 3, N = 3
X[] = {10, 19, 18}, Y[] = {11, 15, 9}
Output: 2
Explanation: There are total 2 pairs 
where pow(x, y) is greater than pow(y, x) 
Pairs are (10, 11) and (10, 15).


Your Task:
You don't need to read input or print anything. Your task is to complete the function countPairs() which takes array X[], array Y[], m and as input parameters and returns an integer denoting the number of pairs that are true to the given condition. 


Expected Time Complexity: O(N*logN + M*logM)
Expected Auxiliary Space: O(1)


Constraints:
1 ≤ M, N ≤ 105
1 ≤ X[i], Y[i] ≤ 103

 

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.