Problem · Sorting
Pairs
Learn this problemProblem statement
Consider two arrays of integers, a[n] and b[n]. What is the maximum number of pairs that can be formed where a[i] > b[j]? Each element can be in no more than one pair.
Find the maximum number of such possible pairs.
Function
findNumOfPairs(a: int[], b: int[]) → int
Complete the function findNumOfPairs in the editor below.
findNumOfPairs has the following parameters:
int a[n]: an array of integersint b[n]: an array of integers
Returns
int: the maximum number of pairs possible
Examples
Example 1
a = [1, 2, 3]b = [1, 2, 1]return = 2Two ways the maximum number of pairs can be selected:
{a[1], b[0]}={2, 1} and {a[2], b[2]}={3, 1} are valid pairs.
{a[1], b[0]}={2, 1} and {a[2], b[1]}={3, 2} are valid pairs.
No more than 2 pairs can be formed, so return 2.
Example 2
a = [1, 2, 3, 4, 5]b = [6, 6, 1, 1, 1]return = 3Valid paris are {a[1], b[2]}, {a[2], b[3]}, {a[3], b[4]} or {2, 1}, {3, 1}, {4, 1}
Example 3
a = [2, 3, 3]b = [3, 4, 5]return = 0Since all the elements of b are greater than each element of a, no pair can be formed T~T
Constraints
1 <= n <= 10^51 <= a[i] <= 10^91 <= b[i] <= 10^9
More JPMorgan Chase problems
- Bitwise XOR SubsequencesOA · Seen Jul 2026
- Array ChallengeOA · Seen Jun 2026
- Minimum Cores to Handle ProcessesOA · Seen Jun 2026
- About ShippingOA · Seen Jun 2026
- Count Dropped RequestsOA · Seen Jan 2026
- Generate Table of ContentsOA · Seen Jan 2026
- Calculate Net ProfitSeen Jun 2025
- Find Total WeightSeen Jun 2025