Given a list of string pairs where each pair represents mutually synonymous words (aliases), return a grouped listing/mapping of all connected synonym components. For example, input: [["a", "b"], ["b", "c"], ["d", "e"]], output: {"a": ["a", "b", "c"], "d": ["d", "e"]}.
Asked in the Phone Screen stage. Coding question asked during phone screen for SDE under ASE.
Implement group_synonyms(pairs). Return a dictionary whose keys are the lexicographically smallest words in each component and whose values are lexicographically sorted component lists. Return {} for empty input.
Example: [["x", "y"], ["y", "z"]] returns { "x": ["x", "y", "z"] }.
def group_synonyms(pairs):