You are given two arrays of positive integers, targets and candidates, and a non-negative integer tolerance.
A target x can be matched with a candidate y when |x - y| <= tolerance. Each target matches at most one candidate and each candidate matches at most one target.
Return the maximum possible number of matched pairs.
Examples
Example 1
Input: targets = [60,45,80,60], candidates = [30,60,75], tolerance = 5
Output: 2
Explanation: Match target 60 with candidate 60 and target 80 with candidate 75. Candidate 30 is too far from every remaining target, so 2 is the maximum.
Example 2
Input: targets = [10, 20], candidates = [15], tolerance = 0
Output: 0
Explanation: With tolerance 0 only exact equality matches, and 15 equals neither target.
Constraints
1≤targets.length, candidates.length≤2⋅105
0≤tolerance≤109
1≤targets[i], candidates[i]≤109
Loading editor...
Log in to run your code. Your draft is saved in this browser.Log inSign up