Count Player Teams by Shared Letters
Updated
Problem statement
You are given an array players, where each string is the lowercase English name of one player.
Two players are directly connected when their names contain at least one common letter. A team is a connected component under this rule: players connected through other players belong to the same team even if their own names share no letter.
Return the number of teams.
Function
countPlayerTeams(players: String[]) → intExamples
Example 1
players = ["ab","bc","de","ef"]return = 2The first two names form one team through b. The last two form another through e.
Example 2
players = ["abc","cde","efg"]return = 1The first and second names share c, and the second and third share e. Transitivity puts all three players on one team.
Example 3
players = ["amy","bob","cyd"]return = 2Amy and Cyd share y. Bob has no letter in common with either of them.
Constraints
0 <= players.length <= 200000.- Every name has length between
1and100. - Names contain only lowercase English letters.
- The sum of all name lengths is at most
2000000.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Record Linkage Part 3 - Full Connected ComponentStripe · PHONE SCREENStripe interview questions
- Sentence Equivalence with SynonymsRead AI · PHONE SCREEN
- Count Distinct Word MeaningsDuolingo · OADuolingo interview questions
- Evaluate DivisionPlaud · ONSITE INTERVIEW
- Evaluate Formulas with Cycle DetectionInstacart · PHONE SCREEN · ONSITE INTERVIEWInstacart interview questions
- Count Friend CirclesOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Radar Barrier CrossingSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
- Minimum Cost for Roads and HospitalsAmazon · ONSITE INTERVIEW
- Validate and Complete Racer PrecedenceMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Accounts MergeOracle · ONSITE INTERVIEWOracle interview questions