Group Attribute-Connected Triplets
Updated
Problem statement
Each row of entries is one entity with exactly three distinct string attributes. Two entities are directly connected when their rows share at least one exact attribute.
Connections can form a chain: entries connected through other entries belong to the same group. Return every connected component as an array of entry indices. Sort indices within a component, and sort components by their first index.
Repeated attributes across any number of rows connect all of those rows. Attribute matching is case-sensitive.
Function
groupAttributeTriplets(entries: String[][]) → int[][]Examples
Example 1
entries = [["a","b","c"],["c","d","e"],["x","y","z"]]return = [[0,1],[2]]Entries 0 and 1 share attribute c; entry 2 is isolated.
Example 2
entries = [["a","b","c"],["d","e","f"],["c","d","g"]]return = [[0,1,2]]Entry 2 transitively joins the first two entries through c and d.
Example 3
entries = []return = []No entries produce no components.
Constraints
0 <= entries.length <= 200000.- Every row contains exactly three distinct attributes.
- Attributes contain
1through30letters or digits. - The total number of attribute characters is at most
5000000.
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
- Package Install OrderVerily · ONSITE INTERVIEW
- Evaluate DivisionPlaud · ONSITE INTERVIEW
- Validate and Resolve Evaluation ChainsPlaid · PHONE SCREEN · ONSITE INTERVIEWPlaid interview questions
- Page Referrer ReachabilityAmazon · ONSITE INTERVIEW
- Count Friend CirclesOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Root of the Largest TreeGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
- Accounts MergeOracle · ONSITE INTERVIEWOracle interview questions
- Query Whether an Island Size ExistsMeta · ONSITE INTERVIEWMeta interview questions
- Reachable Nodes in a Directed GraphSoFi · ONSITE INTERVIEWSoFi interview questions
- DAG Downstream NodesNotion · ONSITE INTERVIEWNotion interview questions