Problem · Array
Maximum Distinct Values After Swaps
Learn this problemProblem statement
You are given two integer arrays a and b and an integer k. In one operation, choose any index in a and any index in b, then swap those two elements.
Return the maximum possible number of distinct values in a after at most k operations.
Function
maximumDistinctAfterSwaps(a: int[], b: int[], k: int) → intExamples
Example 1
a = [1,1,2,2]b = [3,4,1,5]k = 2return = 4Swap one duplicate 1 and one duplicate 2 for 3 and 4. The first array then has four distinct values.
Constraints
1 <= a.length, b.length <= 2000000 <= k <= 200000-10^9 <= a[i], b[i] <= 10^9