Minimum Number Of People To Teach!!!
\n\n# Code\njava []\nclass Solution {\n    public int minimumTeachings(int n, int[][] languages, int[][] friendships) {\n        //Step 1: Creating a map \n    
\n\n# Code\n```java []\nclass Solution {\n    public int minimumTeachings(int n, int[][] languages, int[][] friendships) {\n        //Step 1: Creating a map \n        // language --> person speaking\n        HashMap<Integer, ArrayList<Integer>> map = new HashMap<>();\n        for(int i = 0; i < languages.length; i++){\n            for(int j = 0; j < languages[i].length; j++){\n                int l = languages[i][j];\n                if(!map.containsKey(l)){\n                    map.put(l, new ArrayList<>());\n                }\n                ArrayList<Integer> a = map.get(l);\n                a.add(i + 1);\n                map.put(l,a);\n            }\n        }\n\n        //Step 2: Identifying the pairs which donot share the same language\n        boolean []teachPair = new boolean [friendships.length];\n        for(int i = 0; i < friendships.length; i++){\n            int u = friendships[i][0];\n            int v = friendships[i][1];\n            boolean canCommunicate = false;\n            for(int j = 1; j <= n; j++){\n                if(map.getOrDefault(j, new ArrayList<>()).contains(u) && \n                    map.getOrDefault(j, new ArrayList<>()).contains(v)){\n                    canCommunicate = true;\n                    break;\n                }\n            }\n            if(!canCommunicate) teachPair[i] = true;\n        }\n\n        //Step 3: Finding the minimum number of users we need to teach\n        int m = friendships.length;\n        int minTeachings = Integer.MAX_VALUE;\n\n        for(int i = 1; i <= n ; i++){\n            HashSet<Integer> set = new HashSet<>();\n            for(int j = 0; j < m; j++){\n                if(teachPair[j]){\n                    int u = friendships[j][0];\n                    int v = friendships[j][1];\n\n                    if (!map.getOrDefault(i, new ArrayList<>()).contains(u)) {\n                        set.add(u);\n                    }\n                    if (!map.getOrDefault(i, new ArrayList<>()).contains(v)) {\n                        set.add(v);\n                    }\n                }\n            }\n            minTeachings = Math.min(minTeachings, set.size());\n        }\n        return minTeachings;\n    }\n}\n```
['Array', 'Hash Table', 'Java']