Java simple solution
\nclass Solution {\n  public int minimumTeachings(int n, int[][] languages, int[][] friendships) {\n\n    // record the languages known to every user\n    Map<I
```\nclass Solution {\n  public int minimumTeachings(int n, int[][] languages, int[][] friendships) {\n\n    // record the languages known to every user\n    Map<Integer,Set<Integer>> ul = new HashMap<>();\n    for(int i=0; i<languages.length; i++) {\n      Set<Integer> lang = new HashSet<>();\n      ul.put(i+1, lang);\n      for(int l : languages[i]) {\n        lang.add(l);\n      }\n    }\n\n    // if two users are friends and they can\'t speak to each other due to language issue, record it\n    Map<Integer,Set<Integer>> uf = new HashMap<>();\n    for(int i=0; i<friendships.length; i++) {\n      int[] frnd = friendships[i];\n      boolean canSpk = false;\n      for(int l : ul.get(frnd[0])) {\n        if(ul.get(frnd[1]).contains(l)) {\n          canSpk = true;\n          break;\n        }\n      }\n      if(canSpk) continue;\n      \n      uf.putIfAbsent(frnd[0],new HashSet<>());\n      uf.putIfAbsent(frnd[1],new HashSet<>());\n      uf.get(frnd[0]).add(frnd[1]);\n      uf.get(frnd[1]).add(frnd[0]);\n    }\n    \n    int ans = Integer.MAX_VALUE;\n    // for every language, see how many users need to learn it\n    for(int i=1; i<=n; i++) {\n      int tot = 0;\n    // if we have to teach language i, then how many users need to learn this?\n      for(int key : uf.keySet()) {\n        if(!ul.get(key).contains(i)) tot++;\n      }\n      // if this language needs to be learned by less number of people, then this is the answer, else don\'t override the ans\n      ans = Math.min(ans, tot);\n    }\n    \n    return ans;\n  }\n}\n\n\n```
[]