Beats 100%💯  Easy to understand c++
\n\n# Approach\nUse Hashmaps to store freq of both arrays.Add unique elements of both arrays in the set.If space left add duplicate elements:)\n\n# Complexity\n
\n\n# Approach\nUse Hashmaps to store freq of both arrays.Add unique elements of both arrays in the set.If space left add duplicate elements:)\n\n# Complexity\n- Time complexity:\nO(N1+N2)\n\n- Space complexity:\nO(N1+N2)\n\n# Code\n```\nclass Solution {\npublic:\n    int maximumSetSize(vector<int>& nums1, vector<int>& nums2) {\n       unordered_set<int>res;\n       unordered_map<int, int> f1;\n        unordered_map<int, int> f2;\n        \n        for (auto it : nums1) {\n            f1[it]++;\n        }\n        for (auto it : nums2) {\n            f2[it]++;\n        }\n        int td2=nums2.size()/2;\n        int td1=td2;\n        for(auto it:nums2)\n        {\n            if(f1[it]==0 && td2!=0 && res.find(it)==res.end())\n            {\n                res.insert(it);\n                td2--;\n            }\n        }\n         for(auto it:nums1)\n        {\n            if(f2[it]==0 && td1!=0 && res.find(it)==res.end())\n            {\n                res.insert(it);\n                td1--;\n            }\n        }\n        while(td1!=0)\n        {\n         for(auto it:nums1)\n         {\n            if(f2[it]>0 && td1!=0 && res.find(it)==res.end())\n            {\n                res.insert(it);\n                td1--;\n            }\n            if(td1==0)\n            break;\n         }\n         break;\n        }\n         while(td2!=0)\n        {\n         for(auto it:nums2)\n         {\n            if(f1[it]>0 && td2!=0 && res.find(it)==res.end())\n            {\n                res.insert(it);\n                td2--;\n            }\n            if(td2==0)\n            break;\n         }\n         break;\n        }\n        return res.size();\n    }\n};\n\n```
['C++']