[Time & Memory 100%] Try all languages and find minimum
Complexity\nTime: O(m * n)\nSpace: O(m * n)\n\ntypescript\nfunction minimumTeachings(n: number, languages: number[][], friendships: number[][]): number {\n    /
### Complexity\nTime: `O(m * n)`\nSpace: `O(m * n)`\n\n```typescript\nfunction minimumTeachings(n: number, languages: number[][], friendships: number[][]): number {\n    // filter the friends who do not have a common language and need to be taught\n\tconst friendshipsWithProblem = []\n    for (const [f1, f2] of friendships) {\n        const f1Lang = languages[f1-1]\n        const f2Lang = languages[f2-1]\n        if (!hasCommonLang(f1Lang, f2Lang)) {\n            friendshipsWithProblem.push([f1, f2])\n        }\n    }\n\t\n\t// change language to Sets to reduce time complexity\n    const lang = languages.map(language => new Set(language))\n\t\n\t// try all languages and find the min\n    let min = Infinity\n    for (let i=1; i<=n; i+=1) {\n        min = Math.min(min, teachLang(i, lang, friendshipsWithProblem))\n    }\n    return min\n};\n\n// checking if two people have a common language\nfunction hasCommonLang(lang1: number[], lang2: number[]) {\n    const set = new Set(lang1)\n\treturn lang2.some(lang => set.has(lang))\n}\n\n// finding the number of people needed to be taught for a chosen language \nfunction teachLang(language: number, lang: Set<number>[], friendships: number[][]) {\n    let n = 0\n    \n    for (const [f1, f2] of friendships) {\n        if (!lang[f1-1].has(language)) {\n            lang[f1-1].add(language)\n            n += 1\n        }\n        if (!lang[f2-1].has(language)) {\n            lang[f2-1].add(language)\n            n += 1\n        }\n    }\n    \n    return n\n}\n```
['Ordered Set', 'TypeScript', 'JavaScript']