Simple || Straightforward
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\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```java []\nclass Solution {\n    public int maximumSetSize(int[] nums1, int[] nums2) {\n        int n = nums1.length;\n        HashMap<Integer, Integer> hm1 = new HashMap<>();\n        HashMap<Integer, Integer> hm2 = new HashMap<>();\n        int cnt1 = 0, cnt2 = 0;\n        for (int i : nums1) {\n            if (hm1.containsKey(i))\n                cnt1++;\n            hm1.put(i, hm1.getOrDefault(i, 0) + 1);\n\n        }\n        for (int i : nums2) {\n            if (hm2.containsKey(i))\n                cnt2++;\n            hm2.put(i, hm2.getOrDefault(i, 0) + 1);\n        }\n        int r1 = hm1.size(), r2 = hm2.size();\n                     int common=findCommon(nums1,nums2);\n\n\n        if (cnt1 < n / 2) {\n            int remove =n / 2 - cnt1;\n            if(remove<=common)\n            common=common-remove;\n            else\n            common=0;\n             r1 = r1 - remove;\n        }\n         if (cnt2 < n / 2) {\n            int remove =n / 2 - cnt2;\n            if(remove>=common){\n            r2=r2-(remove);\n            common=0;\n            }\n             \n         }\n         return r1 + r2 - common ;\n\n    }\n    public int findCommon(int nums1[],int nums2[])\n    {\n            Set<Integer> set1 = new HashSet<>();\n        for (int num : nums1) {\n            set1.add(num);\n        }\n        \n        // Use another HashSet to store common elements\n        Set<Integer> common = new HashSet<>();\n        for (int num : nums2) {\n            if (set1.contains(num)) {\n                common.add(num);\n            }\n        }\n        \n        // Return the number of common elements\n        return common.size();\n    }\n}\n```
['Java']