Accounts Merge (LC #721) groups accounts that share any email. This is a connected components problem. Use Union-Find: for each account, union all its emails together. Then group emails by their root parent. Map each root back to the account name and collect all emails under that root. Sort emails and format the output. The Union-Find operations run in nearly with path compression and union by rank. Total time is where is average emails per account. Meta calls this a "silent killer" with tricky edge cases.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
$ curl repovive.com/roadmaps/meta-interview-prep/graphs/accounts-merge
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████████████████████████████████████████████████████████████████████