Big And Small
IntuitionApproachComplexity

Time complexity:
O(n)


Space complexity:

Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
O(n)

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```javascript []
/**
 * @param {number[]} nums1
 * @param {number[]} nums2
 * @return {number}
 */
var maximumSetSize = function (nums1, nums2) {
  let s1 = new Set(nums1);
  let s2 = new Set(nums2);
  let n = nums1.length;
  let r1 = n - s1.size;
  let r2 = n - s2.size;
  let sf1 = Math.max(0, n / 2 - r1);
  let sf2 = Math.max(0, n / 2 - r2);
  let smaller;
  let bigger;
  let remFromBig;
  let remFromSmall;
  if (s1.size > s2.size) {
    smaller = s2;
    bigger = s1;
    remFromBig = sf1;
    remFromSmall = sf2;
  } else {
    smaller = s1;
    bigger = s2;
    remFromBig = sf2;
    remFromSmall = sf1;
  }
  for (let s of smaller) {
    if (!remFromBig) {
      break;
    }
    if (bigger.has(s)) {
      bigger.delete(s);
      remFromBig--;
    }
  }
  for (let b of bigger) {
    if (!remFromSmall) {
      break;
    }
    if (smaller.has(b)) {
      smaller.delete(b);
      remFromSmall--;
    }
  }
  for (let s of smaller) {
    bigger.add(s);
  }
  return bigger.size - remFromBig - remFromSmall;
};
```
['JavaScript']