Greedy Approach | Simple Solution | C++
Intuition\nThe value can be seperated into unique and common.\n\n# Approach\nGreedy approach of counting unique and common values.\n\n# Complexity\n- Time compl
# Intuition\nThe value can be seperated into unique and common.\n\n# Approach\nGreedy approach of counting unique and common values.\n\n# Complexity\n- Time complexity:\n-  O(N)\n\n- Space complexity:\n- O(N)\n\n# Code\n```\nclass Solution {\npublic:\n    int maximumSetSize(vector<int>& nums1, vector<int>& nums2) {\n      int m = nums1.size()/2;\n      unordered_map<int,int> mp1,mp2;\n        \n      for(auto &i: nums1){\n          mp1[i]++;\n      }\n      for(auto &i: nums2){\n          mp2[i]++;\n      }\n      int u1 =0, u2 =0, cm = 0;\n      // Counting all unique values in nums1 that is not in nums2\n      // Also counting commong values of in nums1 and nums2 \n      for(auto &i: mp1){\n        if(mp2.find(i.first) == mp2.end()) u1++;\n        else cm++;      \n      }\n      // Counting all unique values in nums2 that is not in nums1\n      for(auto &i: mp2){\n        if(mp1.find(i.first) == mp1.end()) u2++;\n      }\n      // The max values of common from after getting all the unique values\n      int left1 = max(0,min(m-u1,cm)), left2 = max(0,min(m-u2,cm));\n      // The answer would be sum of unique values and commong values   \n      return min(m,u1) + min(m,u2) + min(left1+left2,cm); \n    }\n};\n```
['Greedy', 'Counting', 'C++']