Easy Video Explanation with Proofs 🔥 || Set Intersection 🔥
Intuition\n Describe your first thoughts on how to solve this problem. \nTry to use set and basic of math is required. Try to dry run few scenarios for better u
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTry to use set and basic of math is required. Try to dry run few scenarios for better understanding\n\n# ***Easy Video Explanation***\n\nhttps://youtu.be/crNIGc4zb8s\n\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nBasic\nThe code determines the maximum size of a set formed by merging two sets. It considers the size of the first set, and then iterates through the second set, incrementing the size based on elements not present in the first set, up to half the size of the second set.\n\n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n    O(N*log(N))\n    \n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n    O(N)\n    \n\n# Code\n\n\n```C++ []\nclass Solution {\npublic:\n    int maximumSetSize(vector<int>& v1, vector<int>& v2) {\n        set<int>s1;\n        set<int>s2;\n        for(auto i:v1)\n            s1.insert(i);\n        for(auto i:v2)\n            s2.insert(i);\n        int n=v1.size(),m=v2.size();\n        int x=s1.size(),y=s2.size();\n        int ans=min(n/2,x);\n        int rem=x-ans;\n        int c=0;\n        for(auto i:s2) {\n            if(s1.find(i)==s1.end()) {\n                c++;\n            } else if(rem>0) {\n                c++;\n                rem--;\n            }\n            if(c>=m/2)\n                break;\n        }\n        return ans+c;\n    }\n};\n```\n```python []\nclass Solution:\n    def maximumSetSize(self, v1, v2):\n        s1 = set(v1)\n        s2 = set(v2)\n        n, m = len(v1), len(v2)\n        x, y = len(s1), len(s2)\n        ans = min(n // 2, x)\n        rem = x - ans\n        c = 0\n        for i in s2:\n            if i not in s1:\n                c += 1\n            elif rem > 0:\n                c += 1\n                rem -= 1\n            if c >= m // 2:\n                break\n        return ans + c\n\n```\n```Java []\nimport java.util.HashSet;\nimport java.util.Set;\n\nclass Solution {\n    public int maximumSetSize(int[] v1, int[] v2) {\n        Set<Integer> s1 = new HashSet<>();\n        Set<Integer> s2 = new HashSet<>();\n        for (int i : v1)\n            s1.add(i);\n        for (int i : v2)\n            s2.add(i);\n        int n = v1.length, m = v2.length;\n        int x = s1.size(), y = s2.size();\n        int ans = Math.min(n / 2, x);\n        int rem = x - ans;\n        int c = 0;\n        for (int i : s2) {\n            if (!s1.contains(i)) {\n                c++;\n            } else if (rem > 0) {\n                c++;\n                rem--;\n            }\n            if (c >= m / 2)\n                break;\n        }\n        return ans + c;\n    }\n}\n\n\n```\n\n# ***If you like the solution Please Upvote and subscribe to my youtube channel***\n***It Motivates me to record more videos***\n\n*Thank you* \uD83D\uDE00
['Math', 'Ordered Set', 'C++', 'Java', 'Python3']