Maximum Size of a Set After Removals

You are given two 0-indexed integer arrays nums1 and nums2 of even length n.

You must remove n / 2 elements from nums1 and n / 2 elements from nums2. After the removals, you insert the remaining elements of nums1 and nums2 into a set s.

Return the maximum possible size of the set s.

Example 1
Inputnums1 = [1,2,1,2], nums2 = [1,1,1,1]
Output2
We can remove two occurrences of 1 from nums1 and nums2, leaving values that form s = {1, 2}, and 2 is the maximum possible size.
Example 2
Inputnums1 = [1,2,3,4,5,6], nums2 = [2,3,2,3,2,3]
Output5
After removing selected elements, the remaining arrays can contribute distinct values {1, 2, 3, 4, 5}, and 5 is the maximum possible size.

Constraints

  • n == nums1.length == nums2.length
  • 1 <= n <= 2 * 10^4
  • n is even.
  • 1 <= nums1[i], nums2[i] <= 10^9

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate