Simple with sets
Intuition\nGreedy algorithm: first pick unique elements from each list, then pick common elements.\n\n# Approach\n\nLet A be the (unique) elements that are only
# Intuition\nGreedy algorithm: first pick unique elements from each list, then pick common elements.\n\n# Approach\n\nLet A be the (unique) elements that are only in nums1, let B be the (unique) elements that are only in nums2, and let C be the (unique) elements that are in both.\n\nFirst pick `a = min(n/2, len(A))` elements from A and `b = min(n/2, len(B))` elements from B, which will be unique.\nThen pick `c = min(len(C), n-(a+b))` elements from C since we can pick `n/2-a` common elements from nums1 and `n/2-b` common elements from nums2, but at most `len(C)` common elements overall.\nThe answer is a + b + c.\n\nExample 1: A = [2], B = [], C = [1], n = 4.\n           a = 1, b = 0, c = 1 -> return 2.\n\nExample 2: A = [1,4,5,6], B = [], C = [2,3], n = 6.\n           a = 3, b = 0, c = 2 -> return 5.\n\nExample 3: A = [1,2,3], B = [4,5,6], C = [], n = 6.\n           a = 3, b = 3, c = 0 -> return 6.\n\n\n# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n  int maximumSetSize(List<int> nums1, List<int> nums2) {\n      final set1 = Set<int>.from(nums1);\n      final set2 = Set<int>.from(nums2);\n      final A = set1.difference(set2);\n      final B = set2.difference(set1);\n      final C = set1.intersection(set2);\n      final n = nums1.length;\n      final a = min(A.length, n~/2);\n      final b = min(B.length, n~/2);\n      final c = min(C.length, n-(a+b));\n      return a + b + c;\n  }\n}\n```
['Dart']