LeetCode 721 Accounts Merge - Problem Statement

The problem

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"]]:

Return merged accounts with emails sorted alphabetically.

Constraints: 11 \le accounts.length 1000\le 1000. 11 \le emails per account 10\le 10.