JPMorgan ChaseOA #12
Pairs
Estimated MediumJudge-ready
Topics (AI-labelled)Two PointersGreedy
Form pairs by taking one element each from arrays a and b of equal length, where the element from a must be strictly greater than the element from b. Each position can be used at most once; find the maximum number of pairs.
Input
The first line contains n, the second line contains a, and the third line contains b; 1≤n≤100000, elements are in 1..1000000000, and duplicates are allowed.
Output
Output a single integer answer.
Example 1
Input:
3
1 2 3
1 2 1
Output:
2
Example 2
Input:
5
1 2 3 4 5
6 6 1 1 1
Output:
3
Example 3
Input:
3
2 3 3
3 4 5
Output:
0
Example notes
The outputs of the three public examples are, in order: 2; 3; 0. These answers have been checked by independent enumeration or direct simulation.
Editorial
Loading solution…