Skip to content
Discussion options

You must be logged in to vote

We need to determine the minimum number of users to teach a single language such that every pair of friends can communicate through a common language. The solution involves checking each language as a candidate and calculating how many users need to learn it to satisfy all friendships that currently lack a common language.

Approach

  1. Precompute Language Knowledge: Create a 2D array (knows) where each entry knows[i][j] indicates whether user i knows language j.
  2. Identify Unsatisfied Friendships: For each friendship, check if there exists any common language between the two users. If not, mark both users as needing intervention.
  3. Calculate Teaching Needs per Language: For each language, count …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@kovatz
Comment options

kovatz Sep 10, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Sep 10, 2025
Maintainer Author

Answer selected by kovatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants