Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Number of Pairs

Medium Acceptance 21.82% Points 30.00

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
Samsung Visa IBM Yahoo
Topics
Array
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions