Dashboard
LC #721

Accounts Merge

Pattern · ?GoogleAmazonMetaLinkedIn

Problem

Merge accounts that share any email. Each account has a name and list of emails. Accounts belong to the same person if they share any email.

Constraints

  • 1 ≤ accounts.length ≤ 1000
  • 2 ≤ accounts[i].length ≤ 10
  • 1 ≤ accounts[i][j].length ≤ 30
  • accounts[i][0] is a name (not email)

Example

Input
accounts = [["John","johnsmith@mail.com","john_newyork@mail.com"],["John","johnsmith@mail.com","john00@mail.com"],["Mary","mary@mail.com"]]
Output
[["John","john00@mail.com","john_newyork@mail.com","johnsmith@mail.com"],["Mary","mary@mail.com"]]
Why
Two John accounts share johnsmith@mail.com, so they merge

Spot the pattern

Which pattern cracks it?

Hints

One at a time
Solve on LeetCode ↗