Java solution intuitive
\n\n# Code\n\nclass Solution {\n    public int minimumTeachings(int n, int[][] languages, int[][] friendships) {\n        ArrayList<HashSet<Integer>> lan = new 
\n\n# Code\n```\nclass Solution {\n    public int minimumTeachings(int n, int[][] languages, int[][] friendships) {\n        ArrayList<HashSet<Integer>> lan = new ArrayList<>();\n        for(int i =0;i<languages.length;i++){//converting languages array to list of set for easy search\n            lan.add(new HashSet<>());\n            for(int j=0;j<languages[i].length;j++){lan.get(i).add(languages[i][j]);}\n        }\n        boolean[] com = new boolean[friendships.length];\n        for(int j=0;j<friendships.length;j++){\n            for(int k : lan.get(friendships[j][0]-1)){\n                if(lan.get(friendships[j][1]-1).contains(k)){\n                    com[j]=true; break;\n                }\n            }\n        }\n        int count=1000,cur=0;\n        for(int i=1;i<=n;i++){//finding how many people need to learn ith language\n            cur=0;\n            for(int j=0;j<friendships.length;j++){\n                //boolean com=false;\n                //for(int k : lan.get(e[0]-1)){if(lan.get(e[1]-1).contains(k)){com=true; break;}}\n                if(com[j])continue;\n                if(lan.get(friendships[j][0]-1).contains(i)){\n                    //1stknows\n                    if(lan.get(friendships[j][1]-1).contains(i))continue;//2nd also knows\n                    else{\n                        //2nd dont know 1st know\n                        cur++;\n                        lan.get(friendships[j][1]-1).add(i);\n                    }\n                }else{\n                    //1stdont know\n                    if(lan.get(friendships[j][1]-1).contains(i)){\n                        //2nd know 1st dont know\n                        cur++;\n                        lan.get(friendships[j][0]-1).add(i);\n                    }else{\n                        //1st and 2nd dont know\n                        cur+=2;\n                        lan.get(friendships[j][0]-1).add(i);\n                        lan.get(friendships[j][1]-1).add(i);\n                    }\n                }\n            }\n            count = Math.min(count,cur);\n        }\n        return count;\n    }\n}\n```
['Java']