Accounts Merge
Given a list of accounts where each account contains a name and emails, merge accounts belonging to the same person (accounts that share at least one common email).

30:00

Accounts Merge
medium
Topics
Companies

Given a list of accounts where each account contains a name and emails, merge accounts belonging to the same person (accounts that share at least one common email).

Example 1:
Constraints:
  • 1accounts.length10001 \leq \text{accounts.length} \leq 1000

  • 2accounts[i].length102 \leq \text{accounts}[i].\text{length} \leq 10

  • 1accounts[i][j].length301 \leq \text{accounts}[i][j].\text{length} \leq 30

  • accounts[i][0] consists of English letters.

  • accounts[i][j] (for j>0j > 0) is a valid email.

Input
arr ={"accounts":[["John","[email protected]","[email protected]"],["John","[email protected]","[email protected]"],["Mary","[email protected]"],["John","[email protected]"]]}
Union
Group
Done

Initialize Union-Find structure

Variables
VariableValue
numAccounts4
DepthFunction Call
Stack empty
0/12