Java Accepted Solution
\nclass Solution {\n    public int minimumTeachings(int n, int[][] languages, int[][] friendships) {\n        int result = languages.length;\n        List<Set<I
```\nclass Solution {\n    public int minimumTeachings(int n, int[][] languages, int[][] friendships) {\n        int result = languages.length;\n        List<Set<Integer>> langList = new ArrayList<>();\n        for(int[] userLangs: languages) {\n            Set<Integer> langSet = new HashSet<>();\n            for(int userLang : userLangs) langSet.add(userLang);\n            langList.add(langSet);\n        }\n        List<int[]> fs = new ArrayList<>();\n        for(int[] friendship : friendships) \n            if(noCommonLang(langList.get(friendship[0]-1), langList.get(friendship[1]-1)))\n                fs.add(friendship);\n        for(int lang=1;lang<=n;lang++) {\n            Set<Integer> usersUpdated = new HashSet<>();\n            for(int[] friendship : fs) {\n                if(!langList.get(friendship[0] - 1).contains(lang)) {\n                    langList.get(friendship[0] - 1).add(lang);\n                    usersUpdated.add(friendship[0]-1);\n                }\n                if(!langList.get(friendship[1] - 1).contains(lang)) {\n                    langList.get(friendship[1] - 1).add(lang);\n                    usersUpdated.add(friendship[1]-1);\n                }\n            }\n            result = Math.min(result, usersUpdated.size());\n            for(int user: usersUpdated) \n                langList.get(user).remove(lang);\n        }\n        return result;\n    }\n    private boolean noCommonLang(Set<Integer> set1, Set<Integer> set2) {\n        if(set2.size() < set1.size()) {\n            for(int i:set2)\n                if(set1.contains(i)) return false;\n        } else { \n            for(int i:set1) \n                if(set2.contains(i)) return false;\n        }\n        return true;\n    }\n}\n```
[]