Problem · Array

Maximum Distinct Values After Swaps

Learn this problem
EasyAkuna Capital logoAkuna CapitalFULLTIMEOA

Problem 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) → int

Examples

Example 1

a = [1,1,2,2]b = [3,4,1,5]k = 2return = 4

Swap 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 <= 200000
  • 0 <= k <= 200000
  • -10^9 <= a[i], b[i] <= 10^9

More Akuna Capital problems

drafts saved locally
public int maximumDistinctAfterSwaps(int[] a, int[] b, int k) {
  // write your code here
}
a[1,1,2,2]
b[3,4,1,5]
k2
expected4
checking account