Simple logic | Hashmap & set | O(nlogn)
Approach\n\n1. Remove elements from nums1 which have freq greater than 1.\n2. Remove elements from nums2 which have freq greater than 1.\n3. Remove elements fro
**Approach**\n\n1. Remove elements from nums1 which have freq greater than 1.\n2. Remove elements from nums2 which have freq greater than 1.\n3. Remove elements from nums1 present in nums2.\n4. Remove elements from nums2 present in nums1.\n5. Insert elements int set. \n6. cnt the remaining elements to be removed and remove it from the set.\n\n```\nclass Solution {\npublic:\n    int maximumSetSize(vector<int>& nums1, vector<int>& nums2) {\n        \n       int n = nums1.size();\n       map<int, int> mp1, mp2;\n       int cnt1 = 0, cnt2 = 0;\n        \n       for(int it: nums1) ++mp1[it];\n       for(int it: nums2) ++mp2[it];\n        \n        //delete duplicate elements having cnt greater than 1 in nums1\n        for(int i = 0; i < n; ++i) {\n            if(nums1[i] == -1 || mp1[nums1[i]] == 0) continue;\n            if(cnt1 == n / 2) break;\n            if(mp1[nums1[i]] > 1) {--mp1[nums1[i]]; ++cnt1; nums1[i] = -1;}\n        }\n        \n        //delete duplicate elements having cnt greater than 1 in nums2\n        for(int i = 0; i < n; ++i) {\n            if(nums2[i] == -1 || mp2[nums2[i]] == 0) continue;\n            if(cnt2 == n / 2) break;\n            if(mp2[nums2[i]] > 1) {--mp2[nums2[i]]; ++cnt2; nums2[i] = 1;}\n        }\n        \n        // delete elements in nums1 which are present in nums2\n        for(int i = 0; i < n; ++i) {\n            if(mp1[nums1[i]] == 0 || nums1[i] == -1) continue;\n            if(cnt1 == n / 2) break;\n            if(mp2[nums1[i]] > 0) {--mp1[nums1[i]]; ++cnt1; nums1[i] = -1;}\n        }\n        \n        //delete elements in nums2 which are present in nums1\n        for(int i = 0; i < n; ++i) {\n            if(mp2[nums2[i]] == 0 || nums2[i] == -1) continue;\n            if(cnt2  == n / 2) break;\n            if(mp1[nums2[i]] > 0) {--mp2[nums2[i]]; ++cnt2; nums2[i] = -1;}\n        }\n    \n        \n        set<int> st;\n        \n        //insert elements into set\n        for(int i = 0; i < n; ++i) {\n            if(nums1[i] != -1 && mp1[nums1[i]] > 0) st.insert(nums1[i]);\n            if(nums2[i] != -1 && mp2[nums2[i]] > 0) st.insert(nums2[i]);\n        }\n        \n        // check how many elements remaining to be removed\n        int remain = n - (cnt1 + cnt2);\n        \n        //remove those elements from the set\n        return st.size() - remain;\n    }\n};\n```\n\n\n
['C', 'Ordered Set']