Video Explanation
Explanation\n\nClick here for the video\n\n# Code\n\nclass Solution {\npublic:\n    int maximumSetSize(vector<int>& nums1, vector<int>& nums2) {\n        int n 
# Explanation\n\n[Click here for the video](https://youtu.be/63dNVenHJ_c)\n\n# Code\n```\nclass Solution {\npublic:\n    int maximumSetSize(vector<int>& nums1, vector<int>& nums2) {\n        int n = nums1.size();\n        unordered_map<int, int> m1, m2;\n        \n        for (auto i : nums1) m1[i] ++;\n        for (auto i : nums2) m2[i] ++;\n        \n        int only_in_1 = 0;\n        int only_in_2 = 0;\n        int both = 0;\n        \n        for (auto i : m1) \n            if (m2.find(i.first) != m2.end()) both ++;\n            else only_in_1 ++;\n        \n        for (auto i : m2) \n            if (m1.find(i.first) == m1.end()) only_in_2 ++;\n        \n        only_in_1 = min (only_in_1, n/2);\n        only_in_2 = min (only_in_2, n/2);\n        \n        if (only_in_1 < n/2) {\n            int req = n/2 - only_in_1;\n            int has = min (req, both);\n            \n            both -= has;\n            only_in_1 += has;\n        }\n        if (only_in_2 < n/2) {\n            int req = n/2 - only_in_2;\n            int has = min (req, both);\n            \n            both -= has;\n            only_in_2 += has;\n        }\n        \n        return (only_in_1 + only_in_2);\n    }\n};\n```
['C++']