# LeetCode: Minimum Number Of People To Teach Solution

```.css-ds3kc{display:table-row;}.css-1t8atru{display:table-cell;opacity:0.5;padding-right:var(--chakra-space-6);-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;text-align:right;}1.css-2qghsv{display:table-cell;}function intersection(setA, setB) {2  let _intersection = new Set()3  for (let elem of setB) {4    if (setA.has(elem)) {5      _intersection.add(elem)6    }7  }8  return _intersection9}10
11var minimumTeachings = function (n, languages, friendships) {12  languages = languages.map(l => new Set(l))13  const conflictUsers = new Set()14  for (let [i, j] of friendships) {15    if (!intersection(languages[i - 1], languages[j - 1]).size) {16      conflictUsers.add(i - 1)17      conflictUsers.add(j - 1)18    }19  }20  const languageCount = Array(n).fill(0)21  for (const user of conflictUsers) {22    for (const language of languages[user]) {23      languageCount[language - 1]++24    }25  }26  return conflictUsers.size - Math.max.apply(null, languageCount)27}```

leetcode

## Next Post

LeetCode: Find The Highest Altitude

Jan 24, 2021

Search Posts