← 返回 apple 的题目列表Alias Group Mapping
类型:qbank
Given pairs of words that are bidirectional aliases under a transitive relationship, return a map for every connected alias group. Each key is the lexicographically smallest word in its group, and each value is the group's complete word list in ascending lexicographic order.
Requirements
Accept a two-dimensional string list pairs, where pairs[i] = [word1, word2] means the two words are aliases.
Treat the alias relationship as bidirectional and transitive.
Merge all related words into independent groups.
Return a map whose key is the lexicographically smallest word in each group.
Store every word in that group as the corresponding value, sorted in ascending lexicographic order.
Examples
Input:
[["a", "b"], ["b", "c"], ["d", "e"]]
Output:
{"a": ["a", "b", "c"], "d": ["d", "e"]}