Gamified challenge · Union-find
Each sign-up is one string "Name:email1,email2,...". Two sign-ups that share any email belong to the same person, and so does anything linked to them through a chain of shared emails. Different people may have the same name, but never the same email.
Write mergeAccounts(accounts) (Python: merge_accounts) that returns one list per person: the name first, then all of that person's emails without repeats, in sorted order (plain string order). The people may come in any order.
Example: ["Ava:ava@mail.io,ava.k@web.co", "Ben:ben@post.net", "Ava:ava.k@web.co,ak@post.net", "Ava:ava2@mail.io"] → [["Ava", "ak@post.net", "ava.k@web.co", "ava@mail.io"], ["Ava", "ava2@mail.io"], ["Ben", "ben@post.net"]].
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google