3 sets - Java O(N) | O(N)
Intuition\n Describe your first thoughts on how to solve this problem. \nPure logic, we first should pick non-overlap unique numbers from nums1 up to n/2 as wel
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nPure logic, we first should pick non-overlap unique numbers from `nums1` up to `n/2` as well as non-overlap unique numbers from `nums2` up to `n/2`. We can see these numbers is safe to pick without affecting the rest.\n\nThen we can add the `overlap` on top of picked numbers as long as if the total number is less than `nums1` size.\n\nUse 3 sets to track:\n*  `set1` - unique numbers from `nums1`\n*  `set2` - unique numbers from `nums2`\n*  `overlap` - overlap of `set1 and set2`\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int maximumSetSize(int[] nums1, int[] nums2) {\n        // each set can contribute 0..n/2 unique numbers after removal\n        // first pick unique non-overlap up to n/2 on each set, then add overlap, max by n\n        Set<Integer> set1 = new HashSet<>(), set2 = new HashSet<>(), overlap = new HashSet<>();\n        for (int val:nums1) set1.add(val);\n        for (int val:nums2) set2.add(val);\n        for (int val:set1) \n            if (set2.contains(val)) \n                overlap.add(val);\n        for (int val:overlap) {\n                set1.remove(val);\n                set2.remove(val);\n        }\n        int cnt = 0, len = nums1.length;\n        cnt += Math.min(set1.size(), len/2);\n        cnt += Math.min(set2.size(), len/2);\n        cnt = Math.min(cnt + overlap.size(),len);\n        return cnt;\n    }\n}\n```
['Java']