Set || Easy
Code\n\nclass Solution {\npublic:\n    int maximumSetSize(vector<int>& A, vector<int>& B) {\n        int n=A.size();\n        unordered_set<int>s1(A.begin(),A.e
# Code\n```\nclass Solution {\npublic:\n    int maximumSetSize(vector<int>& A, vector<int>& B) {\n        int n=A.size();\n        unordered_set<int>s1(A.begin(),A.end());\n        unordered_set<int>s2(B.begin(),B.end());\n        int i=0,j=0;\n        unordered_set<int>st;\n        // Add all unique elements first\n\n        for(auto&it:s1){\n            if(i==n/2) break;\n            if(s2.find(it)==s2.end()) {\n                st.insert(it);\n                i++;\n            }\n        }\n        for(auto&it:s2){\n            if(j==n/2) break;\n            if(s1.find(it)==s1.end()) {\n                st.insert(it);\n                j++;\n            }\n        }\n\n        //If we still have some elements left, add duplicates\n\n        if(i<n/2){\n            for(auto&it:s1){\n                if(i==n/2) break;\n                if(s2.find(it)!=s2.end()) {\n                    st.insert(it);\n                    // to add it in different n/2 set from s2\n                    s2.erase(it);\n                    i++;\n                }\n            }\n        }\n        if(j<n/2){\n            for(auto&it:s2){\n                if(j==n/2) break;\n                if(s1.find(it)!=s1.end()) {\n                    st.insert(it);\n                    j++;\n                }\n            }\n        }\n        return st.size();\n    }\n};\n```
['Math', 'Greedy', 'Simulation', 'Ordered Set', 'C++']