A CRM imported customer profiles from several shops. Each profile is an array whose first item is the customer's name and whose other items are email addresses. Two profiles belong to the same customer if they share at least one email, and this is transitive. Profiles of the same customer always have the same name.
Write mergeProfiles(profiles) that returns one entry per customer: the name followed by all of that customer's distinct emails sorted in plain string order (the order sort() uses). Sort the entries by their first email, in the same order.
Input: profiles = [["Ana","ana@shop.io","a.k@mail.io"],["Ben","ben@shop.io"],["Ana","a.k@mail.io","ana.k@work.io"]] Output: [["Ana","a.k@mail.io","ana.k@work.io","ana@shop.io"],["Ben","ben@shop.io"]]
The two Ana profiles share a.k@mail.io, so they merge. "." sorts before "@", so ana.k@work.io comes before ana@shop.io.
Input: profiles = [["Kai","kai@a.io"],["Kai","kai@b.io"]] Output: [["Kai","kai@a.io"],["Kai","kai@b.io"]]
Same name but no shared email, so they stay two customers.
1 <= profiles.length <= 10001 to 10 emails.Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #457 Merge Customer Profiles by Email. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.