111. Accounts Merge
Merge records when they share an email address, including records connected indirectly through other records. Each connected account component becomes one output row.
A shared name alone is not enough to merge accounts. Deduplicate emails, follow the naming-conflict rules, and return independent mutable output rows.
Example 1
Input
[[A,z,x],[A,y,x],[A],[A,k]]
Output
[[A,x,y,z],[A],[A,k]]
Explanation: The first two records share x. Equal name A does not merge the independent name-only or k records.
Example 2
Input
[[Ada,a,b],[Ada,c,d],[Ada,b,c]]
Output
[[Ada,a,b,c,d]]
Explanation: The third record bridges two earlier groups. The final DSU root need not be source index zero.
Example 3
Input
[[Ada,x],[Grace,x]]
Output
IllegalArgumentException
Explanation: A shared exact email with conflicting names violates the declared identity policy.
Example 4
Input
[[A,X@example],[A,x@example]]
Output
two independent rows
Explanation: Identifier matching is case-sensitive; no email-provider normalization is inferred.
Constraints
0 <= accounts.size <= 1050 <= email occurrences <= 2 * 1050 <= total UTF-16 code units <= 2 * 106- Each account begins with a nonempty name. Email identifiers are nonempty strings.
Hints
Hint 1
Treat records as vertices and each exact shared email as a connection.
Hint 2
Remember one first owner per email, checking the declared name-consistency policy.
Hint 3
After all unions, group distinct emails by final roots and emit components by earliest source index.
Submissions
Your recent submissions for this problem.
Checking sign-in…
Discussion
Ask a question or share an approach. Posts are public; avoid personal information and mark solution spoilers clearly.
No discussion yet. Start the conversation with a question about this problem.
Checking sign-in…
Run your code to check the sample cases, or submit it to check the full validation suite.
Shared email joins records; equal names alone do not
[["A","z","x"],["A","y","x"],["A"],["A","k"]]
[["A","x","y","z"],["A"],["A","k"]]