Skip to content

Practice Minimum Number of People to Teach

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1733
LeetCode Problem

Minimum Number of People to Teach

Problem Statement

There are n languages and m users. languages gives the languages each user knows, and each pair in friendships identifies two direct friends. Two friends can communicate when they share at least one language. Choose a single language and teach it to as few users as possible so that every listed friendship can communicate. Friendships are not transitive: only the supplied pairs impose a requirement. Return the smallest number of users taught.

Source: Minimum Number of People to Teach on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 2, languages = [[1],[2],[1,2]], friendships = [[1,2],[1,3],[2,3]]
Output
1

# Example 2

Input
n = 3, languages = [[2],[1,3],[1,2],[3]], friendships = [[1,4],[1,2],[3,4],[2,3]]
Output
2

Constraints

2 <= n <= 500
languages.length == m
1 <= m <= 500
1 <= languages[i].length <= n
1 <= languages[i][j] <= n
1 <= u​​​​​​i < v​​​​​​i <= languages.length
1 <= friendships.length <= 500
All tuples (u​​​​​i, v​​​​​​i) are unique
languages[i] contains only unique values

Related LeetCode Problems

Practice more problems similar to Minimum Number of People to Teach.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.