Very Easy Approach and Short Code in C++
Intuition and Approach\nstep1. find the total friends who can\'t comm. each other\nstep2.find the most comman lang btwn them\nstep3. ans=totalfriendsWhoCantComm
# Intuition and Approach\nstep1. find the total friends who can\'t comm. each other\nstep2.find the most comman lang btwn them\nstep3. ans=totalfriendsWhoCantComm-countOfMaximumComman Lang\n\n\nintuition:- if we know there are 10 people who cant comm. with each and maximum 5 of them know a comman language then minimum answer will be rest 5 should also know the same language in order to reduce the answer.\n\n# Complexity\n- Time complexity:\nO(N*M)\n\n- Space complexity:\nO(N+M)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n bool check(vector<int> &a,vector<int> &b){\n        for(int i=0;i<a.size();i++){\n            for(int j=0;j<b.size();j++){\n                if(a[i]==b[j]) return true;\n            }\n        }\n        return false;\n    }\n\n    int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) {\n        // step1\n        set<int> s; // so that same friend cannot come into the list.\n        for(int i=0;i<friendships.size();i++){\n            if(!check(languages[friendships[i][0]-1],languages[friendships[i][1]-1])){\n                s.insert(friendships[i][0]-1);\n                s.insert(friendships[i][1]-1);\n            }\n        }\n\n        // step2\n        unordered_map<int,int>commanLang;\n        int ans=0;\n        for(auto it=s.begin();it!=s.end();it++){\n            for(int i=0;i<languages[(*it)].size();i++){\n                commanLang[languages[(*it)][i]]++;\n                ans=max(ans,commanLang[languages[(*it)][i]]);\n            }\n        }\n        // step 3\n        return s.size()-ans;\n\n\n    }\n};\n```
['Greedy', 'C++']