Fast Solution - Four Lines of Code
Code #1\nTime complexity: O(fn + mn). Space complexity: O(mn). f - number of friendships, m - users, n - languages\n\nclass Solution:\n    def minimumTeachings(
# Code #1\nTime complexity: $$O(f*n + m*n)$$. Space complexity: $$O(m*n)$$. f - number of friendships, m - users, n - languages\n```\nclass Solution:\n    def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n        userToLang = {u:{*langs} for u,langs in enumerate(languages, 1)}\n        muteUsers = {u for f in friendships if not userToLang[f[0]]&userToLang[f[1]] for u in f}\n        langCntr = Counter(lang for u in muteUsers for lang in userToLang[u])\n\n        return len(muteUsers) - (langCntr and langCntr.most_common(1)[0][1] or 0)\n```\n\n# Code #2\nTime complexity: $$O(f*n + m*n)$$. Space complexity: $$O(m*n+f)$$. f - number of friendships, m - users, n - languages\n```\nclass Solution:\n    def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n        userToLang = {u:{*langs} for u,langs in enumerate(languages, 1)}\n        friendships = [f for f in friendships if not userToLang[f[0]]&userToLang[f[1]]]\n        if not friendships: return 0\n\n        return min(len({u for f in friendships for u in f if l not in userToLang[u]}) for l in range(1,n+1))\n```
['Array', 'Hash Table', 'Counting', 'Python', 'Python3']