Merge contact cards that share an email
Each contact card is a list [name, email, email, ...] with a name and one or more emails. Two cards belong to the same person when they share an email, directly or through a chain of other cards; a shared name alone proves nothing. Return one merged card per person: the name followed by all of that person's emails, sorted and without repeats. The merged cards can be in any order.
Cards of the same person always carry the same name.
Besides the tests, one large input (450 cards) with a ~200 ms limit (scaled to your device's speed): brute force won't pass.
Examples
merge_cards([["Ana","ana@x.io","a@y.io"],["Leo","leo@x.io"],["Ana","a@y.io","ana@z.io"]])→[["Ana","a@y.io","ana@x.io","ana@z.io"],["Leo","leo@x.io"]]merge_cards([["Sam","sam@x.io"],["Sam","sam@y.io"]])→[["Sam","sam@x.io"],["Sam","sam@y.io"]]merge_cards([["Eva","e1@x.io","e2@x.io"],["Eva","e3@x.io","e4@x.io"],["Eva","e4@x.io","e1@x.io"]])→[["Eva","e1@x.io","e2@x.io","e3@x.io","e4@x.io"]]