Python: 5 lines Venn diagram for two sets. Few set operations
Intuition\nIt is clear that duplicate numbers in nums1 and nums2 do not matter. So you can conver them into two sets.\n\nNow some values can overlap so you have
# Intuition\nIt is clear that duplicate numbers in nums1 and nums2 do not matter. So you can conver them into two sets.\n\nNow some values can overlap so you have the following Venn diagram.\n\n![clip_image007\\[1\\].gif](https://assets.leetcode.com/users/images/dafda736-394e-4135-9049-82583da52613_1704601596.873948.gif)\n\nSo you calculate intersection of both sets (in fact you need only number of them).\n\nNow count the maximum number of elements you can take only from set one: `v1` value. Same for set two. And then check if you can combine them and take the intersection (limiting by total number you can take)\n\n\n# Complexity\n- Time complexity: $O(n)$\n- Space complexity: $O(n)$\n\n# Code\n```\nclass Solution:\n  def maximumSetSize(self, nums1: List[int], nums2: List[int]) -> int:\n    n, nums1, nums2 = len(nums1) // 2, set(nums1), set(nums2)\n    len_both = len(nums1 & nums2)\n\n    v1 = min(len(nums1) - len_both, n)\n    v2 = min(len(nums2) - len_both, n)\n    return min(v1 + v2 + len_both, n * 2)\n```
['Python3']