Using only hashset O(N)
Intuition\nTo maximize the set we need to pick most unique elements\n\n# Approach\n1. Get unique elements of num1 in set1 which are not there in set2\n2. Get un
# Intuition\nTo maximize the set we need to pick most unique elements\n\n# Approach\n1. Get unique elements of num1 in set1 which are not there in set2\n2. Get unique elements of num2 in set2 which are not there in set1\n3. Get common elemenets which are available in both set1 and set2\n4. Not we can pick elements from set1, set2, and common such that the size doesn\'t exceed n.\n\n# Complexity\n- Time complexity:\nO(n)\n- Space complexity:\no(n)\n\n# Code\n```java []\nclass Solution {\n    public int maximumSetSize(int[] nums1, int[] nums2) {\n        Set<Integer> set1 = new HashSet<>();\n        Set<Integer> set2 = new HashSet<>();\n\n        for (int num : nums1) {\n            set1.add(num);\n        }\n        int common = 0;\n        for (int num : nums2) {\n            set2.add(num);\n            if (set1.contains(num)) {\n                common++;\n            }\n            set1.remove(num);\n        }\n        for (int num : nums1) {\n            set2.remove(num);\n        }\n\n        // 1 2 3 4\n        int n = nums1.length;\n        int left = (set1.size() <= n / 2) ? set1.size() : n / 2;\n        int right = (set2.size() <= n / 2) ? set2.size() : n / 2;\n        //System.out.println(set1.size() +":"+ set2.size()+ ":"+ common);\n        int result = left + right + common;\n        if(result <= n){\n            return result;\n        }\n        return n;\n    }\n}\n```
['Java']