Given a list of accounts where each account is a name followed by emails, merge accounts belonging to the same person.
Two accounts belong to the same person if they share any email. One person can have multiple names listed (due to typos), but we identify by shared emails.
With accounts = [["John","john@mail.com","john_work@mail.com"],["John","john@mail.com","john_home@mail.com"],["Mary","mary@mail.com"]]:
- First two accounts share "john@mail.com". Merge them.
- Result: [["John","john@mail.com","john_home@mail.com","john_work@mail.com"],["Mary","mary@mail.com"]].
Return merged accounts with emails sorted alphabetically.
Constraints: accounts.length . emails per account .