A shopping app keeps a list of accounts. Each accounts[i] is a list of strings. The first string is the customer's name. All the other strings are email addresses of that account.
Two accounts belong to the same person if they share at least one email. Two different people can have the same name, so a matching name alone proves nothing. Accounts of one person always have the same name.
Merge the accounts of each person into one. The merged account must start with the name, followed by every email of that person in sorted order, with no repeats. Return the merged accounts. You can return the accounts in any order.
Examples
Example 1:
Input: accounts = [["Asha","asha@mail.com","a1@mail.com"],["Ravi","ravi@mail.com"],["Asha","a1@mail.com","asha2@mail.com"]]
Output: [["Asha","a1@mail.com","asha2@mail.com","asha@mail.com"],["Ravi","ravi@mail.com"]]
Explanation: The two Asha accounts share "a1@mail.com", so they are merged.
Example 2:
Input: accounts = [["Neha","n1@mail.com"],["Neha","n2@mail.com"]]
Output: [["Neha","n1@mail.com"],["Neha","n2@mail.com"]]
Explanation: The names match but no email is shared, so these are two people.
Example 3:
Input: accounts = [["Kabir","k3@mail.com","k1@mail.com"],["Kabir","k2@mail.com","k3@mail.com"],["Kabir","k4@mail.com","k2@mail.com"]]
Output: [["Kabir","k1@mail.com","k2@mail.com","k3@mail.com","k4@mail.com"]]
Explanation: The accounts link one after another through shared emails, so all three become one account.