Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
721. Accounts Merge
Bookmark
Input
Basic Merge
Chain Merge
No Merge Needed
All Merge into One
Custom
accounts
=
[["John","j1@ex.com","j2@ex.com"],["John","j2@ex.com","j3@ex.com"],["Mary","m1@ex.com"]]
Union-Find Structure
j1@ex.com
root
j2@ex.com
root
j3@ex.com
root
m1@ex.com
root
Legend:
Default
Processing
Active
Highlight
Union-Find Structure
j1@ex.com
root
j2@ex.com
root
j3@ex.com
root
m1@ex.com
root
Legend:
Default
Processing
Active
Highlight
Union-Find Structure
j1@ex.com
root
j2@ex.com
root
j3@ex.com
root
m1@ex.com
root
Legend:
Default
Processing
Active
Highlight
Union-Find Structure
j1@ex.com
root
j2@ex.com
j3@ex.com
root
m1@ex.com
root
Legend:
Default
Processing
Active
Highlight
Union-Find Structure
j1@ex.com
root
j2@ex.com
j3@ex.com
root
m1@ex.com
root
Legend:
Default
Processing
Active
Highlight
Union-Find Structure
j1@ex.com
root
j2@ex.com
j3@ex.com
m1@ex.com
root
Legend:
Default
Processing
Active
Highlight
Union-Find Structure
j1@ex.com
root
j2@ex.com
j3@ex.com
m1@ex.com
root
Legend:
Default
Processing
Active
Highlight
Union-Find Structure
j1@ex.com
root
j2@ex.com
j3@ex.com
m1@ex.com
root
Legend:
Default
Processing
Active
Highlight
Union-Find Structure
j1@ex.com
root
j2@ex.com
j3@ex.com
m1@ex.com
root
Legend:
Default
Processing
Active
Highlight
Union-Find Structure
j1@ex.com
root
j2@ex.com
j3@ex.com
m1@ex.com
root
Merged Accounts
[0] "John": j1@ex.com, j2@ex.com, j3@ex.com
[1] "Mary": m1@ex.com
Legend:
Default
Processing
Active
Highlight
Union-Find Structure
j1@ex.com
root
j2@ex.com
j3@ex.com
m1@ex.com
root
Merged Accounts
[0] "John": j1@ex.com, j2@ex.com, j3@ex.com
[1] "Mary": m1@ex.com
Legend:
Default
Processing
Active
Highlight
algo
master
.
io
Step:
Given 3 accounts with 4 unique emails. Initialize Union-Find where each email is its own parent.
0 / 10
Input
Basic Merge
Chain Merge
No Merge Needed
All Merge into One
Custom
accounts
=
[["John","j1@ex.com","j2@ex.com"],["John","j2@ex.com","j3@ex.com"],["Mary","m1@ex.com"]]
0 / 10
algo
master
.
io
Step:
Given 3 accounts with 4 unique emails. Initialize Union-Find where each email is its own parent.