Skip to content

Practice Maximum Size of a Set After Removals

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3002
LeetCode Problem

Maximum Size of a Set After Removals

Problem Statement

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.

Source: Maximum Size of a Set After Removals on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums1 = [1,2,1,2], nums2 = [1,1,1,1]
Output
2

# Example 2

Input
nums1 = [1,2,3,4,5,6], nums2 = [2,3,2,3,2,3]
Output
5

# Example 3

Input
nums1 = [1,1,2,2,3,3], nums2 = [4,4,5,5,6,6]
Output
6

Constraints

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

Related LeetCode Problems

Practice more problems similar to Maximum Size of a Set After Removals.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.