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
Input
nums1 = [1,2,1,2], nums2 = [1,1,1,1]Output
2We 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
Input
nums1 = [1,2,3,4,5,6], nums2 = [2,3,2,3,2,3]Output
5After 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