Easy Solution using HashSet in Java
Intuition\n Describe your first thoughts on how to solve this problem. \nWe neet to maximise the size of the final set , so we need unique elements because is r
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe neet to maximise the size of the final set , so we need unique elements because is repeated elements are there they are added once and will not increase the size of final set.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nTake set1 (Store unique elements of first array)\nTake set2 (Store unique elements of second array)\nTake set3 (Store unique elements from both the array)\n\nGet the common element using (set1.size()+set2.size()-set3.size())\n\nNow from set1 we need to take n/2 elements apart from common\nSimilarly from set2 we need to take n/2 elements apart from common\nNow add common element once.\n\nTill now we will get a answer but there are chances that value can be greater than n , so we use ans=Math.min(ans,n)  becuause if n/2 ele is removed from first array and n/2 element is removed from second array then final set will contain max n element.\n\nWe return our final answer.\n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(n)\n\n# Code\n```java []\nclass Solution {\n    public int maximumSetSize(int[] nums1, int[] nums2) {\n        int n=nums1.length;\n        Set<Integer> set1=new HashSet<>();\n        Set<Integer> set2=new HashSet<>();\n        Set<Integer> set3=new HashSet<>();\n\n        for(int ele:nums1)\n        {\n            set1.add(ele);\n            set3.add(ele);\n        } \n        \n        for(int ele:nums2)\n        {\n            set2.add(ele);\n            set3.add(ele);\n        }\n\n        int common=set1.size()+set2.size()-set3.size();\n        int n1=set1.size();\n        int n2=set2.size();\n        int ans=Math.min(n/2,n1-common);\n        ans+=Math.min(n/2,n2-common);\n        ans+=common;\n        ans=Math.min(ans,n);\n        return ans;\n    }\n}\n```
['Java']