Loading...
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.
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.
Input: targets = [10, 20], candidates = [15], tolerance = 0
Output: 0
Explanation: With tolerance 0 only exact equality matches, and 15 equals neither target.
targets.length, candidates.length ≤2⋅105tolerance ≤109targets[i], candidates[i] ≤109Click "Run" to test with sample cases or "Submit" to run all tests.