Using sets, 100% speed
\n\n# Code\npython3 []\nclass Solution:\n    def maximumSetSize(self, nums1: List[int], nums2: List[int]) -> int:\n        target = len(nums1) // 2\n        uni
![image.png](https://assets.leetcode.com/users/images/6c42e1d7-1cce-4159-ab38-32f393b88952_1729378222.730648.png)\n\n# Code\n```python3 []\nclass Solution:\n    def maximumSetSize(self, nums1: List[int], nums2: List[int]) -> int:\n        target = len(nums1) // 2\n        unique1, unique2 = set(nums1), set(nums2)\n        present_in_both = unique1 & unique2\n\n        # Calculate initial removals\n        removals1 = len(nums1) - len(unique1)\n        removals2 = len(nums2) - len(unique2)\n\n        # Remove elements from unique1 until target is met\n        while removals1 < target:\n            if present_in_both:\n                n = present_in_both.pop()\n                unique1.remove(n)\n            else:\n                unique1.pop()\n            removals1 += 1\n\n        # Remove elements from unique2 until target is met\n        while removals2 < target:\n            if present_in_both:\n                n = present_in_both.pop()\n                unique2.remove(n)\n            else:\n                unique2.pop()\n            removals2 += 1\n\n        # Combine remaining elements\n        unique1.update(unique2)\n\n        return len(unique1)\n```
['Python3']