AmazonOA #164
Find Maximum Pairs
Estimated MediumJudge-ready
Topics (AI-labelled)GreedyTwo Pointers
There are two groups of n numbers each; choose a frontend and a backend to form a pair, using each element at most once. Only pairs in which the frontend value is strictly greater than the backend value count; maximize their number.
Input
The first line contains n, the second line contains the frontends, and the third line contains the backends. 1≤n≤100000, values in 1..10^9.
Output
Output a single integer answer.
Example 1
Input:
3
3 1 5
2 2 4
Output:
2
Example 2
Input:
2
2 2
2 2
Output:
0
Example 3
Input:
1
10
1
Output:
1
Example notes
Example 1: pair 3 with 2 and 5 with 4 for 2 pairs; 1 cannot beat any backend. Example 2: equality does not satisfy strictly greater, so there are 0 pairs. Example 3: 10>1, so 1 pair.
Editorial
Loading solution…