C++ hash table solution with explanation and comments
Idea:\n1. Check if there isn\'t common language for a friendship pair, then at least 1 person of the pair must be taught\n2. Count the number of such people (eg
Idea:\n1. Check if there isn\'t common language for a friendship pair, then at least 1 person of the pair must be taught\n2. Count the number of such people (eg. those may need to be taught) who know a certain language and store them in a map\n-> mapping language to number of people who know it\n3. We can get the minimum number of people who need to be taught\n```\nclass Solution \n{\n    public:\n    bool check(vector<int>& a,vector<int>& b)\n    {\n\t\t//to check if a and b has common language (with 2 pointer)\n        int m=a.size(),n=b.size(),p1=0,p2=0;\n        while(p1<m&&p2<n)\n        {\n            if(a[p1]<b[p2]) p1++;\n            else if(a[p1]>b[p2]) p2++;\n            else return true;\n        }\n        return false;\n    }\n    int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) \n    {\n        int m=languages.size(),t=friendships.size();\n        unordered_set<int> total;\n        unordered_map<int,int> overall;\n        for(int i=0;i<m;i++)\n            sort(languages[i].begin(),languages[i].end()); //in order to use 2 pointers to check common language later\n\n        for(int i=0;i<t;i++)\n            if(!check(languages[friendships[i][0]-1],languages[friendships[i][1]-1])) //no common language\n                total.insert(friendships[i][0]),total.insert(friendships[i][1]); //at least 1 of the person must be taught\n\n        int s=total.size(),result=s; //total number of people who might need to be taught\n        \n        for(unordered_set<int>::iterator it=total.begin();it!=total.end();it++)\n        {\n            vector<int>& language=languages[*it-1];\n            for(int i=0;i<language.size();i++) //all languages that current people know\n                overall[language[i]]++; //mapping language to number of people who know it\n        }\n        for(unordered_map<int,int>::iterator it=overall.begin();it!=overall.end();it++)\n            result=min(result,s-it->second); //get the minimum number of people who need to be taught\n\t\t\t\n        return result;\n    }\n};\n```
[]