C# Beats 100% Space/Time
IntuitionUse bool arrays to simplify comparisons.Don't double-count a users language needs.Accumulate wanted languages when the user's can't speak.ApproachEach
# Intuition
Use bool arrays to simplify comparisons.

Don't double-count a users language needs.

Accumulate wanted languages when the user's can't speak.

# Approach
Each user has a bool array indicating what languages they speak.

Each user has a bool array indicating whether they have already requested a language or not.

Keep track of a user's wanted languages so we only count them once.

Accumulates the wanted language counts.

# Complexity
- Time complexity:
$$O(m * n)$$

- Space complexity:
$$O(m * n)$$

# Code
```csharp []
public class Solution {
    public int MinimumTeachings(int n, int[][] languages, int[][] friendships) {
        var numUsers = languages.Length;

        // Accumulates the wanted language counts. 
        var langWanted = new int[n];

        // Each user has a bool[n] indicating what languages they speak.
        var userLangMasks = new bool[numUsers, n];

        // After a user indicates they want a language, we mark it for the user to avoid double-counts.
        var userLangHandled = new bool[numUsers, n];

        // Initialize Language Masks.
        for (var i = 0; i < numUsers; i++) {
            var userLanguages = languages[i];
            foreach (var language in userLanguages) {
                userLangMasks[i, language - 1] = true;
            }
        }

        // Iterate over friendships.
        foreach (var friendShip in friendships) {
            var u1 = friendShip[0] - 1;
            var u2 = friendShip[1] - 1;

            // Check if the users can speak.
            bool canSpeak = false;
            for (var i = 0; i < n; i++) {
                if (userLangMasks[u1, i] && userLangMasks[u2, i]) {
                    canSpeak = true;
                    break;
                }
            }

            // If the users can't speak, accumulate the languages they may need.
            // Only accumulate a language once per user.
            if (!canSpeak) {
                for (var i = 0; i < n; i++) {
                    if (!userLangHandled[u1, i] && !userLangMasks[u1, i]) {
                        langWanted[i]++;
                        userLangHandled[u1, i] = true;
                    }
                    if (!userLangHandled[u2, i] && !userLangMasks[u2, i]) {
                        langWanted[i]++;
                        userLangHandled[u2, i] = true;
                    }
                }
            }
        }

        var minUsers = int.MaxValue;
        for (var i = 0; i < n; i++) {
            minUsers = Math.Min(minUsers, langWanted[i]);
        }

        return minUsers;
    }
}

```
['C#']