Python | Set
\nclass Solution:\n    def cantCommunicate(self, user1: int, user2: int, languages: List[Set[int]]) -> bool:\n        \'\'\'\n        returns True iff user1 and
```\nclass Solution:\n    def cantCommunicate(self, user1: int, user2: int, languages: List[Set[int]]) -> bool:\n        \'\'\'\n        returns True iff user1 and user2 do not know any languages in common\n        \'\'\'\n        return len(languages[user1].intersection(languages[user2])) == 0\n    \n    def needToTeach(self, language: int, languages: List[Set[int]], missingConnections: Set[int]) -> int:\n        \'\'\'\n        returns number of users that have missing connections and do not know `language`\n        \'\'\'\n        return len([user for user in missingConnections if language not in languages[user]])\n    \n    def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n\t\t# users are 1-indexed\n\t\t# we use sets instead of lists to improve linear lookup time to O(1)\n        languages = [None] + [set(List) for List in languages]\n        missingConnections = set()\n        \n\t\t# identify all users that have at least one friend they can\'t communicate to\n        for user1, user2 in friendships:\n            if self.cantCommunicate(user1, user2, languages):\n                missingConnections.add(user1)\n                missingConnections.add(user2)\n        \n\t\t# for each language count how many users with missing connections do not know that language\n\t\t# answer is the minimum of these counts\n        minUsers = len(languages)\n        for language in range(1, n + 1):\n            minUsers = min(minUsers, self.needToTeach(language, languages, missingConnections))\n            if minUsers == 0:\n                return 0\n            \n        return minUsers\n```
['Ordered Set', 'Python']