[JavaScript] 10037. Maximum Size of a Set After Removals
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n\n---\n\n```\nvar maximumSetSize = function (a, b) {\n  function tryTrimToHalf(set1, set2, n) {\n    for (const e of set1)\n      if (set1.size > n / 2)\n        if (set2.has(e)) {\n          set1.delete(e)\n        }\n  }\n  function trimBothToHalf_andMerge(set1, set2, n) {\n    const a = [...set1].slice(0, n / 2)\n    const b = [...set2].slice(0, n / 2)\n    const merged = [...a, ...b]\n    return merged\n  }\n  const n = a.length\n  const set1 = new Set([...a])\n  const set2 = new Set([...b])\n  tryTrimToHalf(set1, set2, n)\n  tryTrimToHalf(set2, set1, n)\n  const merged = trimBothToHalf_andMerge(set2, set1, n)\n  const set = new Set(merged)\n  return set.size <= n ? set.size : n\n}\n```\n\n---\n\nWeekly Contest 379\n\n- Q1 answer - https://leetcode.com/problems/maximum-area-of-longest-diagonal-rectangle/solutions/4520901/javascript-10035-maximum-area-of-longest-diagonal-rectangle/\n\n---\n
['JavaScript']