Easy C++ only Maps Solution| TC: O(n) | SC: O(n)
Approach\n1. feed all the elements from nums1 to map1 (m1)\n2. feed all the elements from nums2 to map2 (m2)\n3. iterate over the m1 and take unique elements on
# Approach\n1. feed all the elements from `nums1` to `map1 (m1)`\n2. feed all the elements from `nums2` to `map2 (m2)`\n3. iterate over the `m1` and take unique elements only, while iterating your are taking only `<=n/2` elements and delete them from map if taken. Maintain a count how much elements you took (lets say `taken1`)\n4. same process for map 2 (`m2`). Maintain a count how much elements you took (lets say `taken2`)\n5. now after this you have left only elements which are common and present in both m1 and m2\n6. iterate over `m1` again and take (`n/2-taken1`) elements and repeat same for `m2`, if taken erase them from another map since they are common and should be taken only once\n(can use`unordered_map` also)\n# Complexity\n- Time complexity:\nO(n)\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution {\npublic:\n    int maximumSetSize(vector<int>& nums1, vector<int>& nums2) {\n        int n = nums1.size();\n        map<int,int> m1;\n        map<int,int> m2;\n\n        for(int i = 0; i<n; i++)\n        {\n            m1[nums1[i]]++;\n            m2[nums2[i]]++;\n        }\n\n        int taken1 = 0;\n        map<int,int> m;\n        for(auto it: m1)\n        {\n            if(taken1<n/2 && !m2.count(it.first))\n            {\n                cout<<it.first<<", ";\n                m[it.first]++;\n                taken1++;\n                m1[it.first] = 0;\n            }\n            else if(taken1>=n/2) break;\n        }\n        int taken2 = 0;\n        cout<<endl;\n        for(auto it: m2)\n        {\n            if(taken2<n/2 && !m1.count(it.first))\n            {\n                cout<<it.first<<", ";\n                m[it.first]++;\n                taken2++;\n                m2[it.first] = 0;\n            }\n            else if(taken2>=n/2) break;\n        }\n\n        for(auto it: m1)\n        {\n            if(taken1<n/2 && it.second > 0)\n            {\n                m[it.first]++;\n                taken1++;\n                m2.erase(it.first);\n            }\n            else if(taken1>=n/2) break;\n        }\n        for(auto it: m2)\n        {\n            if(taken2<n/2 && it.second>0)\n            {\n                m[it.first]++;\n                taken2++;\n                m1.erase(it.first);\n            }\n            else if(taken2>=n/2) break;\n        }\n        return m.size();\n    }\n};\n```
['C++']