Easy to understand | C++ | Sets
Approach\n Describe your approach to solving the problem. \n1. Calculate the number of unique elements in nums1 and nums2 by storing their elements in sets s1 a
# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Calculate the number of unique elements in nums1 and nums2 by storing their elements in sets s1 and s2.\n2. Also calculate total unique elements in both arrays in set s.\n3. The answer is minimum of:\n        a. size of s\n        b. sum of number of unique elements provided by both arrays, which is min(n/2, s1.size) + min(n/2, s2.size)\n\n# Code\n```\nclass Solution {\npublic:\n    int maximumSetSize(vector<int>& nums1, vector<int>& nums2) {\n        set<int> s1, s2, s;\n        int n = nums1.size();\n        for (int x : nums1) {\n            s1.insert(x);\n            s.insert(x);\n        }\n        for (int x : nums2) {\n            s2.insert(x);\n            s.insert(x);\n        }\n        int ans = min(min(n/2, (int)s1.size()) + min(n/2, (int)s2.size()),(int) s.size());\n         \n        return ans;\n    }\n};\n```
['C++']