Given two positive integer arrays arr and brr, determine the number of pairs (x, y) such that xy > yx, where x is an element from arr and y is an element from brr.
Examples
Example 1
Example 1
Input: arr[] = [3, 4, 2], brr[] = [1, 5]
Output: 4
Explanation: There are 4 such pairs: (3, 1), (3, 5), (4, 1), and (4, 5).
Example 2
Example 2
Input: arr[] = [1, 2], brr[] = [1, 2]
Output: 0
Explanation: No valid pairs exist.
Hints
Hint 1
Expected Time Complexity: O((N + M)log(N)).
Hint 2
Expected Auxiliary Space: O(1).
Constraints
1 <= arr.size(), brr.size() <= 10^5
1 <= brr[i], arr[i] <= 10^3
Companies
SamsungVisaIBMYahoo
Topics
Array
Track your submissions
Please log in to review your progress and explore code submissions from other participants.
Unlock the full solution
Please log in to access detailed answers and explanations.
Join the discussion
Please log in to join conversations with other participants.
Solution.csC#JavaPythonC++Javascript
1
2
3
4
5
6
7
8
9
10
Unlock the code editor
Sign in to write, run, and submit your solution against the full test suite.