As reported: ServiceNow Senior Software Engineer (IC3) loop, round 5 (coding, for a second team after the first position was cancelled), Apr 2025: the candidate gave a brute force with two hash maps, then DFS pseudocode.
Each account is [name, email1, email2, …]. Two accounts belong to the same person if they share an email (same name alone is not enough). Merge them: return one account per person as [name, sorted emails…], in any order.
This is LeetCode 721 — Accounts Merge.
Example
[["John","[email protected]","[email protected]"],
["John","[email protected]","[email protected]"],
["Mary","[email protected]"],
["John","[email protected]"]]
->
[["John","[email protected]","[email protected]","[email protected]"],
["Mary","[email protected]"],
["John","[email protected]"]]
Constraints: 1 ≤ accounts.length ≤ 1000; 2 ≤ accounts[i].length ≤ 10; emails are valid and at most 30 characters.
Code runner format: one line with accounts as a JSON array of string arrays. Implement accountsMerge(accounts); the harness sorts the merged accounts and prints them.